Thread: [Pymoul-svn] SF.net SVN: pymoul: [211] xtea/trunk
Status: Alpha
Brought to you by:
tiran
From: <ti...@us...> - 2007-02-28 01:42:14
|
Revision: 211 http://pymoul.svn.sourceforge.net/pymoul/?rev=211&view=rev Author: tiran Date: 2007-02-27 17:42:12 -0800 (Tue, 27 Feb 2007) Log Message: ----------- Moved to package with pyrex optimization Modified Paths: -------------- xtea/trunk/Makefile xtea/trunk/README.txt xtea/trunk/setup.py xtea/trunk/src/xtea.egg-info/SOURCES.txt Added Paths: ----------- xtea/trunk/src/xtea/ xtea/trunk/src/xtea/__init__.py xtea/trunk/src/xtea/_xtea.c xtea/trunk/src/xtea/_xtea.pyx xtea/trunk/src/xtea/xtea.py xtea/trunk/src/xtea.egg-info/native_libs.txt Removed Paths: ------------- xtea/trunk/src/xtea.py Property Changed: ---------------- xtea/trunk/ Property changes on: xtea/trunk ___________________________________________________________________ Name: svn:ignore + build dist Modified: xtea/trunk/Makefile =================================================================== --- xtea/trunk/Makefile 2007-02-27 16:22:39 UTC (rev 210) +++ xtea/trunk/Makefile 2007-02-28 01:42:12 UTC (rev 211) @@ -9,30 +9,33 @@ all: inplace # Build in-place -inplace: +inplace: pyrex $(PYTHON) setup.py $(SETUPFLAGS) build_ext -i -build: +build: pyrex $(PYTHON) setup.py $(SETUPFLAGS) build +pyrex: + pyrexc src/xtea/_xtea.pyx + egg24: $(PYTHON24) setup.py $(SETUPFLAGS) bdist_egg egg25: $(PYTHON25) setup.py $(SETUPFLAGS) bdist_egg -dist25: +dist25: realclean build $(PYTHON25) setup.py $(SETUPFLAGS) bdist_egg \ sdist --formats=zip,gztar -dist_upload: realclean +dist_upload: realclean build $(PYTHON25) setup.py $(SETUPFLAGS) bdist_egg \ sdist --formats=zip,gztar \ upload --sign --identity=$(KEYID) # What should the default be? test: - $(PYTHON) xtea.py + $(PYTHON) src/xtea/xtea.py egg: egg24 egg25 Modified: xtea/trunk/README.txt =================================================================== --- xtea/trunk/README.txt 2007-02-27 16:22:39 UTC (rev 210) +++ xtea/trunk/README.txt 2007-02-28 01:42:12 UTC (rev 211) @@ -3,6 +3,8 @@ Author: Paul Chakravarti (paul_dot_chakravarti_at_mac_dot_com) License: Public Domain +pyrex optimization: Christian Heimes + This module provides a Python implementation of the XTEA block encryption algorithm (http://www.cix.co.uk/~klockstone/xtea.pdf). Modified: xtea/trunk/setup.py =================================================================== --- xtea/trunk/setup.py 2007-02-27 16:22:39 UTC (rev 210) +++ xtea/trunk/setup.py 2007-02-28 01:42:12 UTC (rev 211) @@ -28,6 +28,7 @@ # import the rest from setuptools import setup from setuptools import find_packages +from setuptools import Extension from distutils.core import setup @@ -60,9 +61,9 @@ 'Programming Language :: Python', 'Topic :: Software Development :: Libraries' ), + ext_modules=[Extension('xtea._xtea', ['src/xtea/_xtea.c'])], setup_requires = ["setuptools>="+SETUPTOOLS_VERSION,], - #packages = ['xtea'], - py_modules = ['xtea'], + packages = ['xtea'], package_dir = {'' : 'src'}, zip_safe = True, ) Property changes on: xtea/trunk/src/xtea ___________________________________________________________________ Name: svn:ignore + _xtea.so Added: xtea/trunk/src/xtea/__init__.py =================================================================== --- xtea/trunk/src/xtea/__init__.py (rev 0) +++ xtea/trunk/src/xtea/__init__.py 2007-02-28 01:42:12 UTC (rev 211) @@ -0,0 +1,6 @@ +# xtea package +from xtea import crypt +from xtea import xtea_encrypt +from xtea import xtea_encryptQuad +from xtea import xtea_decrypt +from xtea import xtea_decryptQuad Property changes on: xtea/trunk/src/xtea/__init__.py ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: xtea/trunk/src/xtea/_xtea.c =================================================================== --- xtea/trunk/src/xtea/_xtea.c (rev 0) +++ xtea/trunk/src/xtea/_xtea.c 2007-02-28 01:42:12 UTC (rev 211) @@ -0,0 +1,391 @@ +/* Generated by Pyrex 0.9.4.1 on Wed Feb 28 02:39:57 2007 */ + +#include "Python.h" +#include "structmember.h" +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif +#ifdef __cplusplus +#define __PYX_EXTERN_C extern "C" +#else +#define __PYX_EXTERN_C extern +#endif +__PYX_EXTERN_C double pow(double, double); + + +typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/ +typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/ +static PyObject *__Pyx_UnpackItem(PyObject *, int); /*proto*/ +static int __Pyx_EndUnpack(PyObject *, int); /*proto*/ +static int __Pyx_PrintItem(PyObject *); /*proto*/ +static int __Pyx_PrintNewline(void); /*proto*/ +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ +static void __Pyx_ReRaise(void); /*proto*/ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/ +static PyObject *__Pyx_GetExcValue(void); /*proto*/ +static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name); /*proto*/ +static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ +static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds, char *kwd_list[], int nargs, PyObject **args2, PyObject **kwds2); /*proto*/ +static void __Pyx_WriteUnraisable(char *name); /*proto*/ +static void __Pyx_AddTraceback(char *funcname); /*proto*/ +static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, long size); /*proto*/ +static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ +static int __Pyx_GetVtable(PyObject *dict, void *vtabptr); /*proto*/ +static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, char *modname); /*proto*/ +static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/ +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ + +static PyObject *__pyx_m; +static PyObject *__pyx_b; +static int __pyx_lineno; +static char *__pyx_filename; +static char **__pyx_f; + +/* Declarations from _xtea */ + + +/* Implementation of _xtea */ + +static PyObject *__pyx_n__xtea_encryptQuad; +static PyObject *__pyx_n__xtea_decryptQuad; + +static PyObject *__pyx_f_5_xtea__xtea_encryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5_xtea__xtea_encryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + unsigned long __pyx_v_v0; + unsigned long __pyx_v_v1; + PyObject *__pyx_v_key = 0; + int __pyx_v_rounds; + int __pyx_v_i; + unsigned long __pyx_v_delta; + unsigned long __pyx_v_sum; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + PyObject *__pyx_3 = 0; + PyObject *__pyx_4 = 0; + PyObject *__pyx_5 = 0; + unsigned long __pyx_6; + static char *__pyx_argnames[] = {"v0","v1","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "kkOi", __pyx_argnames, &__pyx_v_v0, &__pyx_v_v1, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_key); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":11 */ + __pyx_v_delta = 2654435769; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":12 */ + __pyx_v_sum = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":13 */ + __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; goto __pyx_L1;} + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":15 */ + for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_rounds; ++__pyx_v_i) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":16 */ + __pyx_1 = PyLong_FromUnsignedLong(__pyx_v_v0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + __pyx_2 = PyLong_FromUnsignedLong((((__pyx_v_v1 << 4) ^ (__pyx_v_v1 >> 5)) + __pyx_v_v1)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_sum); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + __pyx_4 = PyLong_FromUnsignedLong((__pyx_v_sum & 3)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + Py_DECREF(__pyx_4); __pyx_4 = 0; + __pyx_4 = PyNumber_Add(__pyx_3, __pyx_5); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + Py_DECREF(__pyx_5); __pyx_5 = 0; + __pyx_3 = PyNumber_Xor(__pyx_2, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + Py_DECREF(__pyx_4); __pyx_4 = 0; + __pyx_5 = PyNumber_Add(__pyx_1, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + __pyx_v_v0 = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":17 */ + __pyx_v_sum = (__pyx_v_sum + __pyx_v_delta); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":18 */ + __pyx_2 = PyLong_FromUnsignedLong(__pyx_v_v1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + __pyx_4 = PyLong_FromUnsignedLong((((__pyx_v_v0 << 4) ^ (__pyx_v_v0 >> 5)) + __pyx_v_v0)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + __pyx_1 = PyLong_FromUnsignedLong(__pyx_v_sum); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(((__pyx_v_sum >> 11) & 3)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_3 = PyNumber_Add(__pyx_1, __pyx_5); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_5); __pyx_5 = 0; + __pyx_1 = PyNumber_Xor(__pyx_4, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + Py_DECREF(__pyx_4); __pyx_4 = 0; + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_5 = PyNumber_Add(__pyx_2, __pyx_1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + __pyx_v_v1 = __pyx_6; + __pyx_L2:; + } + __pyx_L3:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":20 */ + __pyx_4 = PyLong_FromUnsignedLong(__pyx_v_v0); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_v1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;} + __pyx_2 = PyList_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_2, 0, __pyx_4); + PyList_SET_ITEM(__pyx_2, 1, __pyx_3); + __pyx_4 = 0; + __pyx_3 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_2; + __pyx_2 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":21 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_3); + Py_XDECREF(__pyx_4); + Py_XDECREF(__pyx_5); + __Pyx_AddTraceback("_xtea._xtea_encryptQuad"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + +static PyObject *__pyx_f_5_xtea__xtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5_xtea__xtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + unsigned long __pyx_v_v0; + unsigned long __pyx_v_v1; + PyObject *__pyx_v_key = 0; + int __pyx_v_rounds; + int __pyx_v_i; + unsigned long __pyx_v_delta; + unsigned long __pyx_v_sum; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + PyObject *__pyx_3 = 0; + PyObject *__pyx_4 = 0; + PyObject *__pyx_5 = 0; + unsigned long __pyx_6; + static char *__pyx_argnames[] = {"v0","v1","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "kkOi", __pyx_argnames, &__pyx_v_v0, &__pyx_v_v1, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_key); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":27 */ + __pyx_v_delta = 2654435769; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":28 */ + __pyx_v_sum = (__pyx_v_delta * __pyx_v_rounds); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":29 */ + __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":31 */ + for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_rounds; ++__pyx_v_i) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":32 */ + __pyx_1 = PyLong_FromUnsignedLong(__pyx_v_v1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + __pyx_2 = PyLong_FromUnsignedLong((((__pyx_v_v0 << 4) ^ (__pyx_v_v0 >> 5)) + __pyx_v_v0)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_sum); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + __pyx_4 = PyLong_FromUnsignedLong(((__pyx_v_sum >> 11) & 3)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + Py_DECREF(__pyx_4); __pyx_4 = 0; + __pyx_4 = PyNumber_Add(__pyx_3, __pyx_5); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + Py_DECREF(__pyx_5); __pyx_5 = 0; + __pyx_3 = PyNumber_Xor(__pyx_2, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + Py_DECREF(__pyx_4); __pyx_4 = 0; + __pyx_5 = PyNumber_Subtract(__pyx_1, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + __pyx_v_v1 = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":33 */ + __pyx_v_sum = (__pyx_v_sum - __pyx_v_delta); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ + __pyx_2 = PyLong_FromUnsignedLong(__pyx_v_v0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_4 = PyLong_FromUnsignedLong((((__pyx_v_v1 << 4) ^ (__pyx_v_v1 >> 5)) + __pyx_v_v1)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_1 = PyLong_FromUnsignedLong(__pyx_v_sum); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong((__pyx_v_sum & 3)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_3 = PyNumber_Add(__pyx_1, __pyx_5); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_5); __pyx_5 = 0; + __pyx_1 = PyNumber_Xor(__pyx_4, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_4); __pyx_4 = 0; + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_5 = PyNumber_Subtract(__pyx_2, __pyx_1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + __pyx_v_v0 = __pyx_6; + __pyx_L2:; + } + __pyx_L3:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":36 */ + __pyx_4 = PyLong_FromUnsignedLong(__pyx_v_v0); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_v1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} + __pyx_2 = PyList_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_2, 0, __pyx_4); + PyList_SET_ITEM(__pyx_2, 1, __pyx_3); + __pyx_4 = 0; + __pyx_3 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_2; + __pyx_2 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":37 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_3); + Py_XDECREF(__pyx_4); + Py_XDECREF(__pyx_5); + __Pyx_AddTraceback("_xtea._xtea_decryptQuad"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + +static __Pyx_InternTabEntry __pyx_intern_tab[] = { + {&__pyx_n__xtea_decryptQuad, "_xtea_decryptQuad"}, + {&__pyx_n__xtea_encryptQuad, "_xtea_encryptQuad"}, + {0, 0} +}; + +static struct PyMethodDef __pyx_methods[] = { + {"_xtea_encryptQuad", (PyCFunction)__pyx_f_5_xtea__xtea_encryptQuad, METH_VARARGS|METH_KEYWORDS, 0}, + {"_xtea_decryptQuad", (PyCFunction)__pyx_f_5_xtea__xtea_decryptQuad, METH_VARARGS|METH_KEYWORDS, 0}, + {0, 0, 0, 0} +}; + +static void __pyx_init_filenames(void); /*proto*/ + +PyMODINIT_FUNC init_xtea(void); /*proto*/ +PyMODINIT_FUNC init_xtea(void) { + __pyx_init_filenames(); + __pyx_m = Py_InitModule4("_xtea", __pyx_methods, 0, 0, PYTHON_API_VERSION); + if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}; + __pyx_b = PyImport_AddModule("__builtin__"); + if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}; + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}; + if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":23 */ + return; + __pyx_L1:; + __Pyx_AddTraceback("_xtea"); +} + +static char *__pyx_filenames[] = { + "_xtea.pyx", +}; + +/* Runtime support code */ + +static void __pyx_init_filenames(void) { + __pyx_f = __pyx_filenames; +} + +static int __Pyx_InternStrings(__Pyx_InternTabEntry *t) { + while (t->p) { + *t->p = PyString_InternFromString(t->s); + if (!*t->p) + return -1; + ++t; + } + return 0; +} + +#include "compile.h" +#include "frameobject.h" +#include "traceback.h" + +static void __Pyx_AddTraceback(char *funcname) { + PyObject *py_srcfile = 0; + PyObject *py_funcname = 0; + PyObject *py_globals = 0; + PyObject *empty_tuple = 0; + PyObject *empty_string = 0; + PyCodeObject *py_code = 0; + PyFrameObject *py_frame = 0; + + py_srcfile = PyString_FromString(__pyx_filename); + if (!py_srcfile) goto bad; + py_funcname = PyString_FromString(funcname); + if (!py_funcname) goto bad; + py_globals = PyModule_GetDict(__pyx_m); + if (!py_globals) goto bad; + empty_tuple = PyTuple_New(0); + if (!empty_tuple) goto bad; + empty_string = PyString_FromString(""); + if (!empty_string) goto bad; + py_code = PyCode_New( + 0, /*int argcount,*/ + 0, /*int nlocals,*/ + 0, /*int stacksize,*/ + 0, /*int flags,*/ + empty_string, /*PyObject *code,*/ + empty_tuple, /*PyObject *consts,*/ + empty_tuple, /*PyObject *names,*/ + empty_tuple, /*PyObject *varnames,*/ + empty_tuple, /*PyObject *freevars,*/ + empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + __pyx_lineno, /*int firstlineno,*/ + empty_string /*PyObject *lnotab*/ + ); + if (!py_code) goto bad; + py_frame = PyFrame_New( + PyThreadState_Get(), /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + py_globals, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + py_frame->f_lineno = __pyx_lineno; + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_srcfile); + Py_XDECREF(py_funcname); + Py_XDECREF(empty_tuple); + Py_XDECREF(empty_string); + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} Property changes on: xtea/trunk/src/xtea/_xtea.c ___________________________________________________________________ Name: svn:eol-style + native Added: xtea/trunk/src/xtea/_xtea.pyx =================================================================== --- xtea/trunk/src/xtea/_xtea.pyx (rev 0) +++ xtea/trunk/src/xtea/_xtea.pyx 2007-02-28 01:42:12 UTC (rev 211) @@ -0,0 +1,37 @@ +# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> +# pyrexc optimized version +# License: Public Domain + +ctypedef unsigned long ULong + +def _xtea_encryptQuad(ULong v0, ULong v1, key, int rounds): + cdef int i + cdef ULong delta, sum + + delta=0x9E3779B9 + sum=0 + result = [] + + for i from 0 <= i < rounds: + v0 = v0 + (((v1<<4 ^ v1>>5) + v1) ^ (sum + key[sum & 3])) + sum = sum + delta + v1 = v1 + (((v0<<4 ^ v0>>5) + v0) ^ (sum + key[sum>>11 & 3])) + + result = [v0, v1] + return result + +def _xtea_decryptQuad(ULong v0, ULong v1, key, int rounds): + cdef int i + cdef ULong delta, sum + + delta=0x9E3779B9 + sum=delta*rounds + result = [] + + for i from 0 <= i < rounds: + v1 = v1 - (((v0<<4 ^ v0>>5) + v0) ^ (sum + key[sum>>11 & 3])) + sum = sum - delta + v0 = v0 - (((v1<<4 ^ v1>>5) + v1) ^ (sum + key[sum & 3])) + + result = [v0, v1] + return result Added: xtea/trunk/src/xtea/xtea.py =================================================================== --- xtea/trunk/src/xtea/xtea.py (rev 0) +++ xtea/trunk/src/xtea/xtea.py 2007-02-28 01:42:12 UTC (rev 211) @@ -0,0 +1,170 @@ +""" +XTEA Block Encryption Algorithm + +Author: Paul Chakravarti (paul_dot_chakravarti_at_mac_dot_com) +License: Public Domain + +This module provides a Python implementation of the XTEA block encryption +algorithm (http://www.cix.co.uk/~klockstone/xtea.pdf). + +The module implements the basic XTEA block encryption algortithm +(`xtea_encrypt`/`xtea_decrypt`) and also provides a higher level `crypt` +function which symmetrically encrypts/decrypts a variable length string using +XTEA in OFB mode as a key generator. The `crypt` function does not use +`xtea_decrypt` which is provided for completeness only (but can be used +to support other stream modes - eg CBC/CFB). + +This module is intended to provide a simple 'privacy-grade' Python encryption +algorithm with no external dependencies. The implementation is relatively slow +and is best suited to small volumes of data. Note that the XTEA algorithm has +not been subjected to extensive analysis (though is believed to be relatively +secure - see http://en.wikipedia.org/wiki/XTEA). For applications requiring +'real' security please use a known and well tested algorithm/implementation. + +The security of the algorithm is entirely based on quality (entropy) and +secrecy of the key. You should generate the key from a known random source and +exchange using a trusted mechanism. In addition, you should always use a random +IV to seed the key generator (the IV is not sensitive and does not need to be +exchanged securely) + + >>> import os + >>> iv = 'ABCDEFGH' + >>> z = crypt('0123456789012345','Hello There',iv) + >>> z.encode('hex') + 'fe196d0a40d6c222b9eff3' + >>> crypt('0123456789012345',z,iv) + 'Hello There' + +""" + +import struct + +def crypt(key, data, iv='\00\00\00\00\00\00\00\00', n=32): + """ + Encrypt/decrypt variable length string using XTEA cypher as + key generator (OFB mode) + * key = 128 bit (16 char) + * iv = 64 bit (8 char) + * data = string (any length) + + >>> import os + >>> key = os.urandom(16) + >>> iv = os.urandom(8) + >>> data = os.urandom(10000) + >>> z = crypt(key,data,iv) + >>> crypt(key,z,iv) == data + True + + """ + def keygen(key, iv, n): + while True: + iv = xtea_encrypt(key, iv, n) + for k in iv: + yield ord(k) + xor = [ chr(x^y) for (x, y) in zip(map(ord, data), keygen(key, iv, n)) ] + return "".join(xor) + +def xtea_encrypt(key, block, rounds=32, endian="!"): + """ + Encrypt 64 bit data block using XTEA block cypher + * key = 128 bit (16 char) + * block = 64 bit (8 char) + * n = rounds (default 32) + * endian = byte order (see 'struct' doc - default big/network) + + >>> z = xtea_encrypt('0123456789012345','ABCDEFGH') + >>> z.encode('hex') + 'b67c01662ff6964a' + + Only need to change byte order if sending/receiving from + alternative endian implementation + + >>> z = xtea_encrypt('0123456789012345','ABCDEFGH',endian="<") + >>> z.encode('hex') + 'ea0c3d7c1c22557f' + + """ + v0,v1 = struct.unpack(endian+"2L", block) + k = struct.unpack(endian+"4L", key) + v0, v1 = xtea_encryptQuad(v0, v1, k, rounds) + return struct.pack(endian+"2L", v0, v1) + +def _xtea_encryptQuad(v0, v1, key, rounds=32, delta=0x9e3779b9L, mask=0xffffffffL): + """Encrypt a quad + + @param v0: value 0 + @type v0: int (unsigned long 32) + @param v1: value 1 + @type v1: int (unsigned long 32) + @param key: decryption key + @type key: list[4] int + @param n: rounds + @type n: int + @return: decrypted values + @rtype: list[2] int + """ + sum = 0 + for round in range(rounds): + v0 = (v0 + (((v1<<4 ^ v1>>5) + v1) ^ (sum + key[sum & 3]))) & mask + sum = (sum + delta) & mask + v1 = (v1 + (((v0<<4 ^ v0>>5) + v0) ^ (sum + key[sum>>11 & 3]))) & mask + return v0, v1 + +def xtea_decrypt(key, block, rounds=32, endian="!"): + """ + Decrypt 64 bit data block using XTEA block cypher + * key = 128 bit (16 char) + * block = 64 bit (8 char) + * n = rounds (default 32) + * endian = byte order (see 'struct' doc - default big/network) + + >>> z = 'b67c01662ff6964a'.decode('hex') + >>> xtea_decrypt('0123456789012345',z) + 'ABCDEFGH' + + Only need to change byte order if sending/receiving from + alternative endian implementation + + >>> z = 'ea0c3d7c1c22557f'.decode('hex') + >>> xtea_decrypt('0123456789012345',z,endian="<") + 'ABCDEFGH' + + """ + v0, v1 = struct.unpack(endian+"2L", block) + k = struct.unpack(endian+"4L", key) + v0, v1 = xtea_decryptQuad(v0, v1, k, rounds) + return struct.pack(endian+"2L", v0, v1) + +def _xtea_decryptQuad(v0, v1, key, rounds=32, delta=0x9e3779b9L, mask=0xffffffffL): + """Decrypt a quad + + @param v0: value 0 + @type v0: int (unsigned long 32) + @param v1: value 1 + @type v1: int (unsigned long 32) + @param key: decryption key + @type key: list[4] int + @param rounds: rounds + @type rounds: int + @return: decrypted values + @rtype: list[2] int + """ + sum = (delta * rounds) & mask + for round in range(rounds): + v1 = (v1 - (((v0<<4 ^ v0>>5) + v0) ^ (sum + key[sum>>11 & 3]))) & mask + sum = (sum - delta) & mask + v0 = (v0 - (((v1<<4 ^ v1>>5) + v1) ^ (sum + key[sum & 3]))) & mask + return v0, v1 + +# Try to replace core functions with optimized versions +try: + #raise ImportError + from _xtea import encipher as xtea_encryptQuad + from _xtea import decipher as xtea_decryptQuad +except ImportError, msg: + xtea_encryptQuad = _xtea_encryptQuad + xtea_decryptQuad = _xtea_decryptQuad + +if __name__ == "__main__": + import doctest + doctest.testmod() Property changes on: xtea/trunk/src/xtea/xtea.py ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Modified: xtea/trunk/src/xtea.egg-info/SOURCES.txt =================================================================== --- xtea/trunk/src/xtea.egg-info/SOURCES.txt 2007-02-27 16:22:39 UTC (rev 210) +++ xtea/trunk/src/xtea.egg-info/SOURCES.txt 2007-02-28 01:42:12 UTC (rev 211) @@ -7,9 +7,13 @@ ez_setup.py setup.py version.txt -src/xtea.py +src/xtea/__init__.py +src/xtea/_xtea.c +src/xtea/tests.py +src/xtea/xtea.py src/xtea.egg-info/PKG-INFO src/xtea.egg-info/SOURCES.txt src/xtea.egg-info/dependency_links.txt +src/xtea.egg-info/native_libs.txt src/xtea.egg-info/top_level.txt src/xtea.egg-info/zip-safe Added: xtea/trunk/src/xtea.egg-info/native_libs.txt =================================================================== --- xtea/trunk/src/xtea.egg-info/native_libs.txt (rev 0) +++ xtea/trunk/src/xtea.egg-info/native_libs.txt 2007-02-28 01:42:12 UTC (rev 211) @@ -0,0 +1 @@ +xtea/_xtea.so Property changes on: xtea/trunk/src/xtea.egg-info/native_libs.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Deleted: xtea/trunk/src/xtea.py =================================================================== --- xtea/trunk/src/xtea.py 2007-02-27 16:22:39 UTC (rev 210) +++ xtea/trunk/src/xtea.py 2007-02-28 01:42:12 UTC (rev 211) @@ -1,128 +0,0 @@ -""" -XTEA Block Encryption Algorithm - -Author: Paul Chakravarti (paul_dot_chakravarti_at_mac_dot_com) -License: Public Domain - -This module provides a Python implementation of the XTEA block encryption -algorithm (http://www.cix.co.uk/~klockstone/xtea.pdf). - -The module implements the basic XTEA block encryption algortithm -(`xtea_encrypt`/`xtea_decrypt`) and also provides a higher level `crypt` -function which symmetrically encrypts/decrypts a variable length string using -XTEA in OFB mode as a key generator. The `crypt` function does not use -`xtea_decrypt` which is provided for completeness only (but can be used -to support other stream modes - eg CBC/CFB). - -This module is intended to provide a simple 'privacy-grade' Python encryption -algorithm with no external dependencies. The implementation is relatively slow -and is best suited to small volumes of data. Note that the XTEA algorithm has -not been subjected to extensive analysis (though is believed to be relatively -secure - see http://en.wikipedia.org/wiki/XTEA). For applications requiring -'real' security please use a known and well tested algorithm/implementation. - -The security of the algorithm is entirely based on quality (entropy) and -secrecy of the key. You should generate the key from a known random source and -exchange using a trusted mechanism. In addition, you should always use a random -IV to seed the key generator (the IV is not sensitive and does not need to be -exchanged securely) - - >>> import os - >>> iv = 'ABCDEFGH' - >>> z = crypt('0123456789012345','Hello There',iv) - >>> z.encode('hex') - 'fe196d0a40d6c222b9eff3' - >>> crypt('0123456789012345',z,iv) - 'Hello There' - -""" - -import struct - -def crypt(key,data,iv='\00\00\00\00\00\00\00\00',n=32): - """ - Encrypt/decrypt variable length string using XTEA cypher as - key generator (OFB mode) - * key = 128 bit (16 char) - * iv = 64 bit (8 char) - * data = string (any length) - - >>> import os - >>> key = os.urandom(16) - >>> iv = os.urandom(8) - >>> data = os.urandom(10000) - >>> z = crypt(key,data,iv) - >>> crypt(key,z,iv) == data - True - - """ - def keygen(key,iv,n): - while True: - iv = xtea_encrypt(key,iv,n) - for k in iv: - yield ord(k) - xor = [ chr(x^y) for (x,y) in zip(map(ord,data),keygen(key,iv,n)) ] - return "".join(xor) - -def xtea_encrypt(key,block,n=32,endian="!"): - """ - Encrypt 64 bit data block using XTEA block cypher - * key = 128 bit (16 char) - * block = 64 bit (8 char) - * n = rounds (default 32) - * endian = byte order (see 'struct' doc - default big/network) - - >>> z = xtea_encrypt('0123456789012345','ABCDEFGH') - >>> z.encode('hex') - 'b67c01662ff6964a' - - Only need to change byte order if sending/receiving from - alternative endian implementation - - >>> z = xtea_encrypt('0123456789012345','ABCDEFGH',endian="<") - >>> z.encode('hex') - 'ea0c3d7c1c22557f' - - """ - v0,v1 = struct.unpack(endian+"2L",block) - k = struct.unpack(endian+"4L",key) - sum,delta,mask = 0L,0x9e3779b9L,0xffffffffL - for round in range(n): - v0 = (v0 + (((v1<<4 ^ v1>>5) + v1) ^ (sum + k[sum & 3]))) & mask - sum = (sum + delta) & mask - v1 = (v1 + (((v0<<4 ^ v0>>5) + v0) ^ (sum + k[sum>>11 & 3]))) & mask - return struct.pack(endian+"2L",v0,v1) - -def xtea_decrypt(key,block,n=32,endian="!"): - """ - Decrypt 64 bit data block using XTEA block cypher - * key = 128 bit (16 char) - * block = 64 bit (8 char) - * n = rounds (default 32) - * endian = byte order (see 'struct' doc - default big/network) - - >>> z = 'b67c01662ff6964a'.decode('hex') - >>> xtea_decrypt('0123456789012345',z) - 'ABCDEFGH' - - Only need to change byte order if sending/receiving from - alternative endian implementation - - >>> z = 'ea0c3d7c1c22557f'.decode('hex') - >>> xtea_decrypt('0123456789012345',z,endian="<") - 'ABCDEFGH' - - """ - v0,v1 = struct.unpack(endian+"2L",block) - k = struct.unpack(endian+"4L",key) - delta,mask = 0x9e3779b9L,0xffffffffL - sum = (delta * n) & mask - for round in range(n): - v1 = (v1 - (((v0<<4 ^ v0>>5) + v0) ^ (sum + k[sum>>11 & 3]))) & mask - sum = (sum - delta) & mask - v0 = (v0 - (((v1<<4 ^ v1>>5) + v1) ^ (sum + k[sum & 3]))) & mask - return struct.pack(endian+"2L",v0,v1) - -if __name__ == "__main__": - import doctest - doctest.testmod() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-02-28 11:59:38
|
Revision: 213 http://pymoul.svn.sourceforge.net/pymoul/?rev=213&view=rev Author: tiran Date: 2007-02-28 03:59:37 -0800 (Wed, 28 Feb 2007) Log Message: ----------- Renamed some functions Modified Paths: -------------- xtea/trunk/setup.py xtea/trunk/src/xtea/__init__.py xtea/trunk/src/xtea/_xtea.c xtea/trunk/src/xtea/_xtea.pyx xtea/trunk/src/xtea/xtea.py Modified: xtea/trunk/setup.py =================================================================== --- xtea/trunk/setup.py 2007-02-28 01:53:29 UTC (rev 212) +++ xtea/trunk/setup.py 2007-02-28 11:59:37 UTC (rev 213) @@ -16,6 +16,7 @@ __revision__ = "$Revision: 203 $" import sys +import os if sys.version_info < (2,4): raise RuntimeError("Python 2.4+ required:\n%s" % sys.version) @@ -37,6 +38,10 @@ me = "Christian Heimes" email = "chr...@ch..." +ext_modules = [] +if os.name == 'posix': + ext_modules.append(Extension('xtea._xtea', ['src/xtea/_xtea.c'])) + setup_infos = dict( name = "xtea", version = VERSION, @@ -61,7 +66,7 @@ 'Programming Language :: Python', 'Topic :: Software Development :: Libraries' ), - ext_modules=[Extension('xtea._xtea', ['src/xtea/_xtea.c'])], + ext_modules=ext_modules, setup_requires = ["setuptools>="+SETUPTOOLS_VERSION,], packages = ['xtea'], package_dir = {'' : 'src'}, Modified: xtea/trunk/src/xtea/__init__.py =================================================================== --- xtea/trunk/src/xtea/__init__.py 2007-02-28 01:53:29 UTC (rev 212) +++ xtea/trunk/src/xtea/__init__.py 2007-02-28 11:59:37 UTC (rev 213) @@ -1,6 +1,6 @@ # xtea package -from xtea import crypt -from xtea import xtea_encrypt -from xtea import xtea_encryptQuad -from xtea import xtea_decrypt -from xtea import xtea_decryptQuad +from xtea.xtea import crypt +from xtea.xtea import xtea_encrypt +from xtea.xtea import xtea_encryptQuad +from xtea.xtea import xtea_decrypt +from xtea.xtea import xtea_decryptQuad Modified: xtea/trunk/src/xtea/_xtea.c =================================================================== --- xtea/trunk/src/xtea/_xtea.c 2007-02-28 01:53:29 UTC (rev 212) +++ xtea/trunk/src/xtea/_xtea.c 2007-02-28 11:59:37 UTC (rev 213) @@ -1,4 +1,4 @@ -/* Generated by Pyrex 0.9.4.1 on Wed Feb 28 02:39:57 2007 */ +/* Generated by Pyrex 0.9.4.1 on Wed Feb 28 12:58:37 2007 */ #include "Python.h" #include "structmember.h" @@ -47,11 +47,11 @@ /* Implementation of _xtea */ -static PyObject *__pyx_n__xtea_encryptQuad; -static PyObject *__pyx_n__xtea_decryptQuad; +static PyObject *__pyx_n__c_xtea_encryptQuad; +static PyObject *__pyx_n__c_xtea_decryptQuad; -static PyObject *__pyx_f_5_xtea__xtea_encryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_f_5_xtea__xtea_encryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_f_5_xtea__c_xtea_encryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5_xtea__c_xtea_encryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { unsigned long __pyx_v_v0; unsigned long __pyx_v_v1; PyObject *__pyx_v_key = 0; @@ -158,7 +158,7 @@ Py_XDECREF(__pyx_3); Py_XDECREF(__pyx_4); Py_XDECREF(__pyx_5); - __Pyx_AddTraceback("_xtea._xtea_encryptQuad"); + __Pyx_AddTraceback("_xtea._c_xtea_encryptQuad"); __pyx_r = 0; __pyx_L0:; Py_DECREF(__pyx_v_result); @@ -166,8 +166,8 @@ return __pyx_r; } -static PyObject *__pyx_f_5_xtea__xtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_f_5_xtea__xtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_f_5_xtea__c_xtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5_xtea__c_xtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { unsigned long __pyx_v_v0; unsigned long __pyx_v_v1; PyObject *__pyx_v_key = 0; @@ -274,7 +274,7 @@ Py_XDECREF(__pyx_3); Py_XDECREF(__pyx_4); Py_XDECREF(__pyx_5); - __Pyx_AddTraceback("_xtea._xtea_decryptQuad"); + __Pyx_AddTraceback("_xtea._c_xtea_decryptQuad"); __pyx_r = 0; __pyx_L0:; Py_DECREF(__pyx_v_result); @@ -283,14 +283,14 @@ } static __Pyx_InternTabEntry __pyx_intern_tab[] = { - {&__pyx_n__xtea_decryptQuad, "_xtea_decryptQuad"}, - {&__pyx_n__xtea_encryptQuad, "_xtea_encryptQuad"}, + {&__pyx_n__c_xtea_decryptQuad, "_c_xtea_decryptQuad"}, + {&__pyx_n__c_xtea_encryptQuad, "_c_xtea_encryptQuad"}, {0, 0} }; static struct PyMethodDef __pyx_methods[] = { - {"_xtea_encryptQuad", (PyCFunction)__pyx_f_5_xtea__xtea_encryptQuad, METH_VARARGS|METH_KEYWORDS, 0}, - {"_xtea_decryptQuad", (PyCFunction)__pyx_f_5_xtea__xtea_decryptQuad, METH_VARARGS|METH_KEYWORDS, 0}, + {"_c_xtea_encryptQuad", (PyCFunction)__pyx_f_5_xtea__c_xtea_encryptQuad, METH_VARARGS|METH_KEYWORDS, 0}, + {"_c_xtea_decryptQuad", (PyCFunction)__pyx_f_5_xtea__c_xtea_decryptQuad, METH_VARARGS|METH_KEYWORDS, 0}, {0, 0, 0, 0} }; Modified: xtea/trunk/src/xtea/_xtea.pyx =================================================================== --- xtea/trunk/src/xtea/_xtea.pyx 2007-02-28 01:53:29 UTC (rev 212) +++ xtea/trunk/src/xtea/_xtea.pyx 2007-02-28 11:59:37 UTC (rev 213) @@ -4,7 +4,7 @@ ctypedef unsigned long ULong -def _xtea_encryptQuad(ULong v0, ULong v1, key, int rounds): +def _c_xtea_encryptQuad(ULong v0, ULong v1, key, int rounds): cdef int i cdef ULong delta, sum @@ -20,7 +20,7 @@ result = [v0, v1] return result -def _xtea_decryptQuad(ULong v0, ULong v1, key, int rounds): +def _c_xtea_decryptQuad(ULong v0, ULong v1, key, int rounds): cdef int i cdef ULong delta, sum Modified: xtea/trunk/src/xtea/xtea.py =================================================================== --- xtea/trunk/src/xtea/xtea.py 2007-02-28 01:53:29 UTC (rev 212) +++ xtea/trunk/src/xtea/xtea.py 2007-02-28 11:59:37 UTC (rev 213) @@ -89,7 +89,8 @@ v0, v1 = xtea_encryptQuad(v0, v1, k, rounds) return struct.pack(endian+"2L", v0, v1) -def _xtea_encryptQuad(v0, v1, key, rounds=32, delta=0x9e3779b9L, mask=0xffffffffL): +def _py_xtea_encryptQuad(v0, v1, key, rounds=32, delta=0x9e3779b9L, + mask=0xffffffffL): """Encrypt a quad @param v0: value 0 @@ -135,7 +136,8 @@ v0, v1 = xtea_decryptQuad(v0, v1, k, rounds) return struct.pack(endian+"2L", v0, v1) -def _xtea_decryptQuad(v0, v1, key, rounds=32, delta=0x9e3779b9L, mask=0xffffffffL): +def _py_xtea_decryptQuad(v0, v1, key, rounds=32, delta=0x9e3779b9L, + mask=0xffffffffL): """Decrypt a quad @param v0: value 0 @@ -159,11 +161,15 @@ # Try to replace core functions with optimized versions try: #raise ImportError - from _xtea import encipher as xtea_encryptQuad - from _xtea import decipher as xtea_decryptQuad + from _xtea import _c_xtea_encryptQuad + from _xtea import _c_xtea_decryptQuad except ImportError, msg: - xtea_encryptQuad = _xtea_encryptQuad - xtea_decryptQuad = _xtea_decryptQuad + print msg + xtea_encryptQuad = _py_xtea_encryptQuad + xtea_decryptQuad = _py_xtea_decryptQuad +else: + xtea_encryptQuad = _c_xtea_encryptQuad + xtea_decryptQuad = _c_xtea_decryptQuad if __name__ == "__main__": import doctest This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-03-01 16:25:42
|
Revision: 219 http://pymoul.svn.sourceforge.net/pymoul/?rev=219&view=rev Author: tiran Date: 2007-03-01 08:25:39 -0800 (Thu, 01 Mar 2007) Log Message: ----------- PEP 272 conform XTEA module with pyrex/c optimization Modified Paths: -------------- xtea/trunk/Makefile xtea/trunk/setup.py xtea/trunk/src/xtea/__init__.py xtea/trunk/src/xtea/_xtea.c xtea/trunk/src/xtea/_xtea.pyx xtea/trunk/src/xtea/xtea.py Added Paths: ----------- xtea/trunk/src/xtea/cxtea.c xtea/trunk/src/xtea/cxtea.h Modified: xtea/trunk/Makefile =================================================================== --- xtea/trunk/Makefile 2007-02-28 12:13:59 UTC (rev 218) +++ xtea/trunk/Makefile 2007-03-01 16:25:39 UTC (rev 219) @@ -9,15 +9,12 @@ all: inplace # Build in-place -inplace: pyrex +inplace: $(PYTHON) setup.py $(SETUPFLAGS) build_ext -i -build: pyrex +build: $(PYTHON) setup.py $(SETUPFLAGS) build -pyrex: - pyrexc src/xtea/_xtea.pyx - egg24: $(PYTHON24) setup.py $(SETUPFLAGS) bdist_egg Modified: xtea/trunk/setup.py =================================================================== --- xtea/trunk/setup.py 2007-02-28 12:13:59 UTC (rev 218) +++ xtea/trunk/setup.py 2007-03-01 16:25:39 UTC (rev 219) @@ -38,9 +38,10 @@ me = "Christian Heimes" email = "chr...@ch..." +cxtea = Extension('xtea._xtea', ['src/xtea/_xtea.pyx', 'src/xtea/cxtea.c']) ext_modules = [] if os.name == 'posix': - ext_modules.append(Extension('xtea._xtea', ['src/xtea/_xtea.c'])) + ext_modules.append(cxtea) setup_infos = dict( name = "xtea", Modified: xtea/trunk/src/xtea/__init__.py =================================================================== --- xtea/trunk/src/xtea/__init__.py 2007-02-28 12:13:59 UTC (rev 218) +++ xtea/trunk/src/xtea/__init__.py 2007-03-01 16:25:39 UTC (rev 219) @@ -1,6 +1,7 @@ # xtea package -from xtea import crypt -from xtea import xtea_encrypt -from xtea import xtea_encryptQuad -from xtea import xtea_decrypt -from xtea import xtea_decryptQuad +from xtea import new +from xtea import MODE_ECB +from xtea import MODE_OFB +from xtea import BIG_ENDIAN +from xtea import LITTLE_ENDIAN +from xtea import NETWORK_ENDIAN Modified: xtea/trunk/src/xtea/_xtea.c =================================================================== --- xtea/trunk/src/xtea/_xtea.c 2007-02-28 12:13:59 UTC (rev 218) +++ xtea/trunk/src/xtea/_xtea.c 2007-03-01 16:25:39 UTC (rev 219) @@ -1,4 +1,4 @@ -/* Generated by Pyrex 0.9.4.1 on Wed Feb 28 12:58:37 2007 */ +/* Generated by Pyrex 0.9.4.1 on Thu Mar 1 15:44:44 2007 */ #include "Python.h" #include "structmember.h" @@ -11,6 +11,7 @@ #define __PYX_EXTERN_C extern #endif __PYX_EXTERN_C double pow(double, double); +#include "cxtea.h" typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/ @@ -47,6 +48,11 @@ /* Implementation of _xtea */ +static PyObject *__pyx_n_MODE_ECB; +static PyObject *__pyx_n_MODE_CBC; +static PyObject *__pyx_n_MODE_CFB; +static PyObject *__pyx_n_MODE_OFB; +static PyObject *__pyx_n_MODE_CTR; static PyObject *__pyx_n__c_xtea_encryptQuad; static PyObject *__pyx_n__c_xtea_decryptQuad; @@ -55,97 +61,74 @@ unsigned long __pyx_v_v0; unsigned long __pyx_v_v1; PyObject *__pyx_v_key = 0; - int __pyx_v_rounds; - int __pyx_v_i; - unsigned long __pyx_v_delta; - unsigned long __pyx_v_sum; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_v[2]); + unsigned long (__pyx_v_k[4]); PyObject *__pyx_v_result; PyObject *__pyx_r; PyObject *__pyx_1 = 0; PyObject *__pyx_2 = 0; - PyObject *__pyx_3 = 0; + unsigned long __pyx_3; PyObject *__pyx_4 = 0; - PyObject *__pyx_5 = 0; - unsigned long __pyx_6; static char *__pyx_argnames[] = {"v0","v1","key","rounds",0}; - if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "kkOi", __pyx_argnames, &__pyx_v_v0, &__pyx_v_v1, &__pyx_v_key, &__pyx_v_rounds)) return 0; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "kkOI", __pyx_argnames, &__pyx_v_v0, &__pyx_v_v1, &__pyx_v_key, &__pyx_v_rounds)) return 0; Py_INCREF(__pyx_v_key); __pyx_v_result = Py_None; Py_INCREF(Py_None); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":11 */ - __pyx_v_delta = 2654435769; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":24 */ + (__pyx_v_v[0]) = __pyx_v_v0; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":12 */ - __pyx_v_sum = 0; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":24 */ + (__pyx_v_v[1]) = __pyx_v_v1; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":13 */ - __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; goto __pyx_L1;} - Py_DECREF(__pyx_v_result); - __pyx_v_result = __pyx_1; - __pyx_1 = 0; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":25 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[0]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":15 */ - for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_rounds; ++__pyx_v_i) { + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":25 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[1]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":16 */ - __pyx_1 = PyLong_FromUnsignedLong(__pyx_v_v0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - __pyx_2 = PyLong_FromUnsignedLong((((__pyx_v_v1 << 4) ^ (__pyx_v_v1 >> 5)) + __pyx_v_v1)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_sum); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - __pyx_4 = PyLong_FromUnsignedLong((__pyx_v_sum & 3)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - Py_DECREF(__pyx_4); __pyx_4 = 0; - __pyx_4 = PyNumber_Add(__pyx_3, __pyx_5); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - Py_DECREF(__pyx_3); __pyx_3 = 0; - Py_DECREF(__pyx_5); __pyx_5 = 0; - __pyx_3 = PyNumber_Xor(__pyx_2, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - Py_DECREF(__pyx_4); __pyx_4 = 0; - __pyx_5 = PyNumber_Add(__pyx_1, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - Py_DECREF(__pyx_5); __pyx_5 = 0; - __pyx_v_v0 = __pyx_6; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":25 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[2]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":17 */ - __pyx_v_sum = (__pyx_v_sum + __pyx_v_delta); + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":25 */ + __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[3]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":18 */ - __pyx_2 = PyLong_FromUnsignedLong(__pyx_v_v1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - __pyx_4 = PyLong_FromUnsignedLong((((__pyx_v_v0 << 4) ^ (__pyx_v_v0 >> 5)) + __pyx_v_v0)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - __pyx_1 = PyLong_FromUnsignedLong(__pyx_v_sum); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - __pyx_3 = PyLong_FromUnsignedLong(((__pyx_v_sum >> 11) & 3)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_3 = PyNumber_Add(__pyx_1, __pyx_5); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - Py_DECREF(__pyx_5); __pyx_5 = 0; - __pyx_1 = PyNumber_Xor(__pyx_4, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - Py_DECREF(__pyx_4); __pyx_4 = 0; - Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_5 = PyNumber_Add(__pyx_2, __pyx_1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - Py_DECREF(__pyx_5); __pyx_5 = 0; - __pyx_v_v1 = __pyx_6; - __pyx_L2:; - } - __pyx_L3:; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":26 */ + encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":20 */ - __pyx_4 = PyLong_FromUnsignedLong(__pyx_v_v0); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;} - __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_v1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;} - __pyx_2 = PyList_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;} - PyList_SET_ITEM(__pyx_2, 0, __pyx_4); - PyList_SET_ITEM(__pyx_2, 1, __pyx_3); - __pyx_4 = 0; - __pyx_3 = 0; - Py_DECREF(__pyx_v_result); - __pyx_v_result = __pyx_2; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":27 */ + __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; goto __pyx_L1;} + __pyx_2 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; goto __pyx_L1;} + __pyx_4 = PyList_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_4, 0, __pyx_1); + PyList_SET_ITEM(__pyx_4, 1, __pyx_2); + __pyx_1 = 0; __pyx_2 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_4; + __pyx_4 = 0; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":21 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":28 */ Py_INCREF(__pyx_v_result); __pyx_r = __pyx_v_result; goto __pyx_L0; @@ -155,9 +138,7 @@ __pyx_L1:; Py_XDECREF(__pyx_1); Py_XDECREF(__pyx_2); - Py_XDECREF(__pyx_3); Py_XDECREF(__pyx_4); - Py_XDECREF(__pyx_5); __Pyx_AddTraceback("_xtea._c_xtea_encryptQuad"); __pyx_r = 0; __pyx_L0:; @@ -171,95 +152,72 @@ unsigned long __pyx_v_v0; unsigned long __pyx_v_v1; PyObject *__pyx_v_key = 0; - int __pyx_v_rounds; - int __pyx_v_i; - unsigned long __pyx_v_delta; - unsigned long __pyx_v_sum; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_v[2]); + unsigned long (__pyx_v_k[4]); PyObject *__pyx_v_result; PyObject *__pyx_r; PyObject *__pyx_1 = 0; PyObject *__pyx_2 = 0; - PyObject *__pyx_3 = 0; + unsigned long __pyx_3; PyObject *__pyx_4 = 0; - PyObject *__pyx_5 = 0; - unsigned long __pyx_6; static char *__pyx_argnames[] = {"v0","v1","key","rounds",0}; - if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "kkOi", __pyx_argnames, &__pyx_v_v0, &__pyx_v_v1, &__pyx_v_key, &__pyx_v_rounds)) return 0; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "kkOI", __pyx_argnames, &__pyx_v_v0, &__pyx_v_v1, &__pyx_v_key, &__pyx_v_rounds)) return 0; Py_INCREF(__pyx_v_key); __pyx_v_result = Py_None; Py_INCREF(Py_None); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":27 */ - __pyx_v_delta = 2654435769; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":33 */ + (__pyx_v_v[0]) = __pyx_v_v0; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":28 */ - __pyx_v_sum = (__pyx_v_delta * __pyx_v_rounds); + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":33 */ + (__pyx_v_v[1]) = __pyx_v_v1; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":29 */ - __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} - Py_DECREF(__pyx_v_result); - __pyx_v_result = __pyx_1; - __pyx_1 = 0; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[0]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":31 */ - for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_rounds; ++__pyx_v_i) { + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[1]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":32 */ - __pyx_1 = PyLong_FromUnsignedLong(__pyx_v_v1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - __pyx_2 = PyLong_FromUnsignedLong((((__pyx_v_v0 << 4) ^ (__pyx_v_v0 >> 5)) + __pyx_v_v0)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_sum); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - __pyx_4 = PyLong_FromUnsignedLong(((__pyx_v_sum >> 11) & 3)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - Py_DECREF(__pyx_4); __pyx_4 = 0; - __pyx_4 = PyNumber_Add(__pyx_3, __pyx_5); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - Py_DECREF(__pyx_3); __pyx_3 = 0; - Py_DECREF(__pyx_5); __pyx_5 = 0; - __pyx_3 = PyNumber_Xor(__pyx_2, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - Py_DECREF(__pyx_4); __pyx_4 = 0; - __pyx_5 = PyNumber_Subtract(__pyx_1, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - Py_DECREF(__pyx_5); __pyx_5 = 0; - __pyx_v_v1 = __pyx_6; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[2]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":33 */ - __pyx_v_sum = (__pyx_v_sum - __pyx_v_delta); + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ + __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[3]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ - __pyx_2 = PyLong_FromUnsignedLong(__pyx_v_v0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - __pyx_4 = PyLong_FromUnsignedLong((((__pyx_v_v1 << 4) ^ (__pyx_v_v1 >> 5)) + __pyx_v_v1)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - __pyx_1 = PyLong_FromUnsignedLong(__pyx_v_sum); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - __pyx_3 = PyLong_FromUnsignedLong((__pyx_v_sum & 3)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_3 = PyNumber_Add(__pyx_1, __pyx_5); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - Py_DECREF(__pyx_5); __pyx_5 = 0; - __pyx_1 = PyNumber_Xor(__pyx_4, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - Py_DECREF(__pyx_4); __pyx_4 = 0; - Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_5 = PyNumber_Subtract(__pyx_2, __pyx_1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - Py_DECREF(__pyx_5); __pyx_5 = 0; - __pyx_v_v0 = __pyx_6; - __pyx_L2:; - } - __pyx_L3:; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":35 */ + decipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":36 */ - __pyx_4 = PyLong_FromUnsignedLong(__pyx_v_v0); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} - __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_v1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} - __pyx_2 = PyList_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} - PyList_SET_ITEM(__pyx_2, 0, __pyx_4); - PyList_SET_ITEM(__pyx_2, 1, __pyx_3); - __pyx_4 = 0; - __pyx_3 = 0; - Py_DECREF(__pyx_v_result); - __pyx_v_result = __pyx_2; + __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} + __pyx_2 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} + __pyx_4 = PyList_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_4, 0, __pyx_1); + PyList_SET_ITEM(__pyx_4, 1, __pyx_2); + __pyx_1 = 0; __pyx_2 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_4; + __pyx_4 = 0; /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":37 */ Py_INCREF(__pyx_v_result); @@ -271,9 +229,7 @@ __pyx_L1:; Py_XDECREF(__pyx_1); Py_XDECREF(__pyx_2); - Py_XDECREF(__pyx_3); Py_XDECREF(__pyx_4); - Py_XDECREF(__pyx_5); __Pyx_AddTraceback("_xtea._c_xtea_decryptQuad"); __pyx_r = 0; __pyx_L0:; @@ -283,6 +239,11 @@ } static __Pyx_InternTabEntry __pyx_intern_tab[] = { + {&__pyx_n_MODE_CBC, "MODE_CBC"}, + {&__pyx_n_MODE_CFB, "MODE_CFB"}, + {&__pyx_n_MODE_CTR, "MODE_CTR"}, + {&__pyx_n_MODE_ECB, "MODE_ECB"}, + {&__pyx_n_MODE_OFB, "MODE_OFB"}, {&__pyx_n__c_xtea_decryptQuad, "_c_xtea_decryptQuad"}, {&__pyx_n__c_xtea_encryptQuad, "_c_xtea_encryptQuad"}, {0, 0} @@ -298,17 +259,44 @@ PyMODINIT_FUNC init_xtea(void); /*proto*/ PyMODINIT_FUNC init_xtea(void) { + PyObject *__pyx_1 = 0; __pyx_init_filenames(); __pyx_m = Py_InitModule4("_xtea", __pyx_methods, 0, 0, PYTHON_API_VERSION); - if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}; + if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}; __pyx_b = PyImport_AddModule("__builtin__"); - if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}; - if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}; - if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}; + if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}; + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}; + if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":23 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":15 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; goto __pyx_L1;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_MODE_ECB, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":16 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_MODE_CBC, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":17 */ + __pyx_1 = PyInt_FromLong(4); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_MODE_CFB, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":18 */ + __pyx_1 = PyInt_FromLong(5); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_MODE_OFB, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":19 */ + __pyx_1 = PyInt_FromLong(6); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; goto __pyx_L1;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_MODE_CTR, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":30 */ return; __pyx_L1:; + Py_XDECREF(__pyx_1); __Pyx_AddTraceback("_xtea"); } Modified: xtea/trunk/src/xtea/_xtea.pyx =================================================================== --- xtea/trunk/src/xtea/_xtea.pyx 2007-02-28 12:13:59 UTC (rev 218) +++ xtea/trunk/src/xtea/_xtea.pyx 2007-03-01 16:25:39 UTC (rev 219) @@ -2,36 +2,36 @@ # pyrexc optimized version # License: Public Domain +# http://www.python.org/dev/peps/pep-0272/ +# http://en.wikipedia.org/wiki/XTEA + ctypedef unsigned long ULong +ctypedef unsigned int UInt -def _c_xtea_encryptQuad(ULong v0, ULong v1, key, int rounds): - cdef int i - cdef ULong delta, sum +cdef extern from "cxtea.h": + void decipher(ULong *v, ULong *k, UInt rounds) + void encipher(ULong *v, ULong *k, UInt rounds) - delta=0x9E3779B9 - sum=0 - result = [] +MODE_ECB = 1 # Electronic Code Book +MODE_CBC = 2 # Cipher Block Chaining +MODE_CFB = 4 # Cipher Feedback +MODE_OFB = 5 # Output Feedback +MODE_CTR = 6 # Counter - for i from 0 <= i < rounds: - v0 = v0 + (((v1<<4 ^ v1>>5) + v1) ^ (sum + key[sum & 3])) - sum = sum + delta - v1 = v1 + (((v0<<4 ^ v0>>5) + v0) ^ (sum + key[sum>>11 & 3])) - - result = [v0, v1] +def _c_xtea_encryptQuad(ULong v0, ULong v1, object key, UInt rounds): + cdef ULong v[2] + cdef ULong k[4] + v[0] = v0; v[1] = v1 + k[0] = key[0]; k[1] = key[1]; k[2] = key[2]; k[3] = key[3]; + encipher(v, k, rounds) + result = [v[0], v[1]] return result -def _c_xtea_decryptQuad(ULong v0, ULong v1, key, int rounds): - cdef int i - cdef ULong delta, sum - - delta=0x9E3779B9 - sum=delta*rounds - result = [] - - for i from 0 <= i < rounds: - v1 = v1 - (((v0<<4 ^ v0>>5) + v0) ^ (sum + key[sum>>11 & 3])) - sum = sum - delta - v0 = v0 - (((v1<<4 ^ v1>>5) + v1) ^ (sum + key[sum & 3])) - - result = [v0, v1] +def _c_xtea_decryptQuad(ULong v0, ULong v1, key, UInt rounds): + cdef ULong v[2] + cdef ULong k[4] + v[0] = v0; v[1] = v1 + k[0] = key[0]; k[1] = key[1]; k[2] = key[2]; k[3] = key[3]; + decipher(v, k, rounds) + result = [v[0], v[1]] return result Added: xtea/trunk/src/xtea/cxtea.c =================================================================== --- xtea/trunk/src/xtea/cxtea.c (rev 0) +++ xtea/trunk/src/xtea/cxtea.c 2007-03-01 16:25:39 UTC (rev 219) @@ -0,0 +1,32 @@ +/* Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> + pyrexc optimized version + License: Public Domain + + Source: http://en.wikipedia.org/wiki/XTEA +*/ + +#include "cxtea.h" + +void decipher(ULong *const v, const ULong *const k, const UInt rounds) + { + register UInt i; + register ULong delta=0x9E3779B9; + register ULong sum=delta*rounds; + for (i=0; i < rounds; i++) { + v[1] -= ((v[0]<<4 ^ v[0]>>5) + v[0]) ^ (sum + k[sum>>11 & 3]); + sum -= delta; + v[0] -= ((v[1]<<4 ^ v[1]>>5) + v[1]) ^ (sum + k[sum & 3]); + } + } + +void encipher(ULong *const v, const ULong *const k, const UInt rounds) + { + register UInt i; + register ULong delta=0x9E3779B9; + register ULong sum=0; + for (i=0; i < rounds; i++) { + v[0] += ((v[1]<<4 ^ v[1]>>5) + v[1]) ^ (sum + k[sum & 3]); + sum += delta; + v[1] += ((v[0]<<4 ^ v[0]>>5) + v[0]) ^ (sum + k[sum>>11 & 3]); + } + } Property changes on: xtea/trunk/src/xtea/cxtea.c ___________________________________________________________________ Name: svn:eol-style + native Added: xtea/trunk/src/xtea/cxtea.h =================================================================== --- xtea/trunk/src/xtea/cxtea.h (rev 0) +++ xtea/trunk/src/xtea/cxtea.h 2007-03-01 16:25:39 UTC (rev 219) @@ -0,0 +1,19 @@ +/* Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> + pyrexc optimized version + License: Public Domain + + Source: http://en.wikipedia.org/wiki/XTEA +*/ + +#define MODE_ECB 1 // Electronic Code Book +#define MODE_CBC 2 // Cipher Block Chaining +#define MODE_CFB 4 // Cipher Feedback +#define MODE_OFB 5 // Output Feedback +#define MODE_CTR 6 // Counter + +typedef unsigned long ULong; +typedef unsigned int UInt; + +void decipher(ULong *const v, const ULong *const k, const UInt rounds); +void encipher(ULong *const v, const ULong *const k, const UInt rounds); + Property changes on: xtea/trunk/src/xtea/cxtea.h ___________________________________________________________________ Name: svn:eol-style + native Modified: xtea/trunk/src/xtea/xtea.py =================================================================== --- xtea/trunk/src/xtea/xtea.py 2007-02-28 12:13:59 UTC (rev 218) +++ xtea/trunk/src/xtea/xtea.py 2007-03-01 16:25:39 UTC (rev 219) @@ -1,7 +1,7 @@ -""" -XTEA Block Encryption Algorithm +"""XTEA Block Encryption Algorithm Author: Paul Chakravarti (paul_dot_chakravarti_at_mac_dot_com) + Christian Heimes (christian (at) cheimes (dot) de) License: Public Domain This module provides a Python implementation of the XTEA block encryption @@ -27,68 +27,189 @@ IV to seed the key generator (the IV is not sensitive and does not need to be exchanged securely) +""" + +from struct import pack +from struct import unpack +import sys + +__all__ = ['new', 'MODE_ECB', 'MODE_OFB', 'BIG_ENDIAN', + 'LITTLE_ENDIAN', 'NETWORK_ENDIAN'] + +MODE_ECB = 1 # Electronic Code Book +MODE_CBC = 2 # Cipher Block Chaining +MODE_CFB = 4 # Cipher Feedback +MODE_OFB = 5 # Output Feedback +MODE_CTR = 6 # Counter +BIG_ENDIAN = 'big' +LITTLE_ENDIAN = 'little' +NETWORK_ENDIAN = LITTLE_ENDIAN +HOST_ENDIAN = sys.byteorder + +class XTEA(object): + """XTEA block cipher (PEP 272 conform implementation) + + Key: 16 chars or tuple with 4 longs (128 bit) + blocksize: 8 (64 bit) + rounds: 32 (default) + endian: little or big endian (default: host endian) + IV: initialization vector for OFB (8 chars) + mode: ECB, OFB + + ECB mode encryption and decryption + >>> xtea = new('0123456789012345', mode=MODE_ECB, endian=LITTLE_ENDIAN) + >>> z = xtea.encrypt('ABCDEFGH') + >>> z.encode('hex') + 'ea0c3d7c1c22557f' + >>> xtea.decrypt(z) + 'ABCDEFGH' + + The block must be 8 characters or a multitude of 8 long + >>> z = xtea.encrypt('ABCDEFGHABCDEFGH') + >>> z.encode('hex') + 'ea0c3d7c1c22557fea0c3d7c1c22557f' + >>> xtea.decrypt(z) + 'ABCDEFGHABCDEFGH' + + You can specify the endianes of the key and data. The default value is host endian. + >>> xtea = new('0123456789012345', mode=MODE_ECB, endian=BIG_ENDIAN) + >>> z = xtea.encrypt('ABCDEFGH') + >>> z.encode('hex') + 'b67c01662ff6964a' + >>> xtea.decrypt(z) + 'ABCDEFGH' + + In OFB mode the data block can have any size. >>> import os + >>> key = os.urandom(16) + >>> iv = os.urandom(8) + >>> data = os.urandom(10000) + >>> xtea = XTEA(key, mode=MODE_OFB, IV=iv, endian=LITTLE_ENDIAN) + >>> z = xtea.encrypt(data) + >>> xtea.decrypt(z) == data + True + + >>> key = '0123456789012345' >>> iv = 'ABCDEFGH' - >>> z = crypt('0123456789012345','Hello There',iv) + >>> xtea = XTEA(key, mode=MODE_OFB, IV=iv, endian=BIG_ENDIAN) + >>> z = xtea.encrypt('Hello There!') >>> z.encode('hex') - 'fe196d0a40d6c222b9eff3' - >>> crypt('0123456789012345',z,iv) - 'Hello There' + 'fe196d0a40d6c222b9eff3e9' + >>> xtea.decrypt(z) + 'Hello There!' + """ + @property + def key_size(self): + return 16 -""" + @property + def block_size(self): + return 8 -import struct + def __init__(self, key, mode=MODE_ECB, IV=None, rounds=32, + endian=HOST_ENDIAN, **kwargs): + if endian == BIG_ENDIAN: + self._endian = ">" + elif endian == LITTLE_ENDIAN: + self._endian = "<" + else: + raise ValueError("Unknown endian: %s" % endian) -def crypt(key, data, iv='\00\00\00\00\00\00\00\00', n=32): - """ - Encrypt/decrypt variable length string using XTEA cypher as - key generator (OFB mode) - * key = 128 bit (16 char) - * iv = 64 bit (8 char) - * data = string (any length) + if isinstance(key, tuple): + if len(key) != 4: + raise ValueError("Invalid key size") + self._key = key + elif isinstance(key, str): + if len(key) != self.key_size: + raise ValueError("Invalid key size") + self._key = unpack(self._endian+"4L", key) + else: + raise TypeError("Invalid key type") - >>> import os - >>> key = os.urandom(16) - >>> iv = os.urandom(8) - >>> data = os.urandom(10000) - >>> z = crypt(key,data,iv) - >>> crypt(key,z,iv) == data - True + if mode == MODE_ECB: + if IV is not None: + raise ValueError("IV not required for ECB") + elif mode == MODE_OFB: + if IV is None or len(IV) != self.block_size: + raise ValueError("Invalid IV") + else: + raise ValueError("Unknown or unsupported mode") - """ - def keygen(key, iv, n): + self._mode = mode + self._rounds = rounds + self._iv = IV + + def encrypt(self, block): + """Encrypt a block + + @param block: block to encrypt + @type block: str + """ + if self._mode == MODE_ECB: + return self._ecb(block, func=xtea_encryptQuad) + elif self._mode == MODE_OFB: + return self._ofb(block) + else: + raise ValueError("Unknown or unsupported mode") + + def decrypt(self, block): + """Decrypt a block + + @param block: block to decrypt + @type block: str + """ + if self._mode == MODE_ECB: + return self._ecb(block, func=xtea_decryptQuad) + elif self._mode == MODE_OFB: + return self._ofb(block) + else: + raise ValueError("Unknown or unsupported mode") + + def _ecb(self, block, func): + """Electronic Code Book encryption/decryption + + @type block: str + @param func: decrypt or encrypt function + @type func: callable(v0, v1, keys[4], rounds) + """ + l = len(block) + bs = self.block_size + key, rounds = self._key, self._rounds + fmt = self._endian+"2L" + result = [] + if l % bs != 0: + raise ValueError + for i in range(l/bs): + v0, v1 = unpack(fmt, block[i*bs:(i+1)*bs]) + w0, w1 = func(v0, v1, key, rounds) + result.append(pack(fmt, w0, w1)) + return ''.join(result) + + def _ofb_keygen(self): + """Key generator + + @return: generator function + """ + key, iv, rounds = self._key, self._iv, self._rounds + fmt = self._endian+"2L" + #v0, v1 = unpack(self._endian+"2L", iv) while True: - iv = xtea_encrypt(key, iv, n) + v0, v1 = unpack(fmt, iv) + w0, w1 = xtea_encryptQuad(v0, v1, key, rounds) + iv = pack(fmt, w0, w1) for k in iv: yield ord(k) - xor = [ chr(x^y) for (x, y) in zip(map(ord, data), keygen(key, iv, n)) ] - return "".join(xor) -def xtea_encrypt(key, block, rounds=32, endian="!"): - """ - Encrypt 64 bit data block using XTEA block cypher - * key = 128 bit (16 char) - * block = 64 bit (8 char) - * n = rounds (default 32) - * endian = byte order (see 'struct' doc - default big/network) + def _ofb(self, block): + """Output Feedback (OFB) encryption requires an IV + """ + key = pack(self._endian+"4L", *self._key) + gen = self._ofb_keygen() + xor = [chr(x^y) for (x, y) in zip(map(ord, block), gen)] + return ''.join(xor) - >>> z = xtea_encrypt('0123456789012345','ABCDEFGH') - >>> z.encode('hex') - 'b67c01662ff6964a' +new = XTEA - Only need to change byte order if sending/receiving from - alternative endian implementation - - >>> z = xtea_encrypt('0123456789012345','ABCDEFGH',endian="<") - >>> z.encode('hex') - 'ea0c3d7c1c22557f' - - """ - v0,v1 = struct.unpack(endian+"2L", block) - k = struct.unpack(endian+"4L", key) - v0, v1 = xtea_encryptQuad(v0, v1, k, rounds) - return struct.pack(endian+"2L", v0, v1) - def _py_xtea_encryptQuad(v0, v1, key, rounds=32, delta=0x9e3779b9L, mask=0xffffffffL): """Encrypt a quad @@ -111,31 +232,6 @@ v1 = (v1 + (((v0<<4 ^ v0>>5) + v0) ^ (sum + key[sum>>11 & 3]))) & mask return v0, v1 -def xtea_decrypt(key, block, rounds=32, endian="!"): - """ - Decrypt 64 bit data block using XTEA block cypher - * key = 128 bit (16 char) - * block = 64 bit (8 char) - * n = rounds (default 32) - * endian = byte order (see 'struct' doc - default big/network) - - >>> z = 'b67c01662ff6964a'.decode('hex') - >>> xtea_decrypt('0123456789012345',z) - 'ABCDEFGH' - - Only need to change byte order if sending/receiving from - alternative endian implementation - - >>> z = 'ea0c3d7c1c22557f'.decode('hex') - >>> xtea_decrypt('0123456789012345',z,endian="<") - 'ABCDEFGH' - - """ - v0, v1 = struct.unpack(endian+"2L", block) - k = struct.unpack(endian+"4L", key) - v0, v1 = xtea_decryptQuad(v0, v1, k, rounds) - return struct.pack(endian+"2L", v0, v1) - def _py_xtea_decryptQuad(v0, v1, key, rounds=32, delta=0x9e3779b9L, mask=0xffffffffL): """Decrypt a quad @@ -160,11 +256,9 @@ # Try to replace core functions with optimized versions try: - #raise ImportError from _xtea import _c_xtea_encryptQuad from _xtea import _c_xtea_decryptQuad except ImportError, msg: - print msg xtea_encryptQuad = _py_xtea_encryptQuad xtea_decryptQuad = _py_xtea_decryptQuad else: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-03-01 16:34:57
|
Revision: 220 http://pymoul.svn.sourceforge.net/pymoul/?rev=220&view=rev Author: tiran Date: 2007-03-01 08:34:49 -0800 (Thu, 01 Mar 2007) Log Message: ----------- Updated READMEs and version Modified Paths: -------------- xtea/trunk/CHANGES.txt xtea/trunk/INSTALL.txt xtea/trunk/LICENSE.txt xtea/trunk/README.txt xtea/trunk/setup.py xtea/trunk/src/xtea.egg-info/PKG-INFO xtea/trunk/src/xtea.egg-info/SOURCES.txt xtea/trunk/version.txt Modified: xtea/trunk/CHANGES.txt =================================================================== --- xtea/trunk/CHANGES.txt 2007-03-01 16:25:39 UTC (rev 219) +++ xtea/trunk/CHANGES.txt 2007-03-01 16:34:49 UTC (rev 220) @@ -0,0 +1,5 @@ +0.1 2007/03/01 + + * PEP 272 style XTEA module + * pyrex + c optimization + * setuptools and eggification Modified: xtea/trunk/INSTALL.txt =================================================================== --- xtea/trunk/INSTALL.txt 2007-03-01 16:25:39 UTC (rev 219) +++ xtea/trunk/INSTALL.txt 2007-03-01 16:34:49 UTC (rev 220) @@ -4,7 +4,11 @@ * Python 2.4+ http://www.python.org/ * easy_install http://peak.telecommunity.com/DevCenter/EasyInstall - * setuptools (via easy install) + * setuptools (via easy install) + + optional: + * C compiler for the optimized C implementation (gcc 4, MinGW32) + * pyrex ============ Installation Modified: xtea/trunk/LICENSE.txt =================================================================== --- xtea/trunk/LICENSE.txt 2007-03-01 16:25:39 UTC (rev 219) +++ xtea/trunk/LICENSE.txt 2007-03-01 16:34:49 UTC (rev 220) @@ -1 +1 @@ -Public Domain \ No newline at end of file +Public Domain Modified: xtea/trunk/README.txt =================================================================== --- xtea/trunk/README.txt 2007-03-01 16:25:39 UTC (rev 219) +++ xtea/trunk/README.txt 2007-03-01 16:34:49 UTC (rev 220) @@ -1,30 +1,25 @@ XTEA Block Encryption Algorithm +=============================== -Author: Paul Chakravarti (paul_dot_chakravarti_at_mac_dot_com) License: Public Domain -pyrex optimization: Christian Heimes +Authors: Paul Chakravarti (paul_dot_chakravarti_at_mac_dot_com) + Christian Heimes (christian (at) cheimes (dot) de) -This module provides a Python implementation of the XTEA block encryption -algorithm (http://www.cix.co.uk/~klockstone/xtea.pdf). -The module implements the basic XTEA block encryption algortithm -(`xtea_encrypt`/`xtea_decrypt`) and also provides a higher level `crypt` -function which symmetrically encrypts/decrypts a variable length string using -XTEA in OFB mode as a key generator. The `crypt` function does not use -`xtea_decrypt` which is provided for completeness only (but can be used -to support other stream modes - eg CBC/CFB). +Paul Chakravarti: + * Initial implementation of the XTEA algorithm for Python. -This module is intended to provide a simple 'privacy-grade' Python encryption -algorithm with no external dependencies. The implementation is relatively slow -and is best suited to small volumes of data. Note that the XTEA algorithm has -not been subjected to extensive analysis (though is believed to be relatively -secure - see http://en.wikipedia.org/wiki/XTEA). For applications requiring -'real' security please use a known and well tested algorithm/implementation. +Christian Heimes: + * PEP 272 conform implementation using the original crypt(), xtea_decrypt() + and xtea_encrypt() functions from Paul Chakravarti. -The security of the algorithm is entirely based on quality (entropy) and -secrecy of the key. You should generate the key from a known random source and -exchange using a trusted mechanism. In addition, you should always use a random -IV to seed the key generator (the IV is not sensitive and does not need to be -exchanged securely) + * Pyrex/C optimization written based on the wikipedia entry + http://en.wikipedia.org/wiki/XTEA + * setup.py, Makefile and eggification + + + + + Modified: xtea/trunk/setup.py =================================================================== --- xtea/trunk/setup.py 2007-03-01 16:25:39 UTC (rev 219) +++ xtea/trunk/setup.py 2007-03-01 16:34:49 UTC (rev 220) @@ -33,7 +33,7 @@ from distutils.core import setup -VERSION = "1.0" +VERSION = "0.1" me = "Christian Heimes" email = "chr...@ch..." @@ -59,7 +59,8 @@ keywords = ["xtea", "crypt", "encryption", "decryption"], platforms = ['Independent'], classifiers = ( - 'Development Status :: 6 - Mature', + #'Development Status :: 6 - Mature', + 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: Public Domain', 'Operating System :: OS Independent' @@ -75,4 +76,3 @@ ) setup(**setup_infos) - Modified: xtea/trunk/src/xtea.egg-info/PKG-INFO =================================================================== --- xtea/trunk/src/xtea.egg-info/PKG-INFO 2007-03-01 16:25:39 UTC (rev 219) +++ xtea/trunk/src/xtea.egg-info/PKG-INFO 2007-03-01 16:34:49 UTC (rev 220) @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: xtea -Version: 1.0 +Version: 0.1 Summary: XTEA Block Encryption Algorithm Home-page: http://sourceforge.net/projects/pymoul/ Author: Christian Heimes @@ -20,7 +20,7 @@ Keywords: xtea,crypt,encryption,decryption Platform: Independent -Classifier: Development Status :: 6 - Mature +Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: Public Domain Classifier: Operating System :: OS IndependentNatural Language :: English Modified: xtea/trunk/src/xtea.egg-info/SOURCES.txt =================================================================== --- xtea/trunk/src/xtea.egg-info/SOURCES.txt 2007-03-01 16:25:39 UTC (rev 219) +++ xtea/trunk/src/xtea.egg-info/SOURCES.txt 2007-03-01 16:34:49 UTC (rev 220) @@ -9,7 +9,9 @@ version.txt src/xtea/__init__.py src/xtea/_xtea.c -src/xtea/tests.py +src/xtea/_xtea.pyx +src/xtea/cxtea.c +src/xtea/cxtea.h src/xtea/xtea.py src/xtea.egg-info/PKG-INFO src/xtea.egg-info/SOURCES.txt Modified: xtea/trunk/version.txt =================================================================== --- xtea/trunk/version.txt 2007-03-01 16:25:39 UTC (rev 219) +++ xtea/trunk/version.txt 2007-03-01 16:34:49 UTC (rev 220) @@ -1 +1 @@ -1.0 +0.1 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-03-01 17:33:37
|
Revision: 221 http://pymoul.svn.sourceforge.net/pymoul/?rev=221&view=rev Author: tiran Date: 2007-03-01 09:33:31 -0800 (Thu, 01 Mar 2007) Log Message: ----------- Added tests.py Modified Paths: -------------- xtea/trunk/Makefile xtea/trunk/README.txt Added Paths: ----------- xtea/trunk/src/xtea/tests.py Modified: xtea/trunk/Makefile =================================================================== --- xtea/trunk/Makefile 2007-03-01 16:34:49 UTC (rev 220) +++ xtea/trunk/Makefile 2007-03-01 17:33:31 UTC (rev 221) @@ -32,7 +32,7 @@ # What should the default be? test: - $(PYTHON) src/xtea/xtea.py + PYTHONPATH=src $(PYTHON) src/xtea/tests.py egg: egg24 egg25 Modified: xtea/trunk/README.txt =================================================================== --- xtea/trunk/README.txt 2007-03-01 16:34:49 UTC (rev 220) +++ xtea/trunk/README.txt 2007-03-01 17:33:31 UTC (rev 221) @@ -7,19 +7,18 @@ Christian Heimes (christian (at) cheimes (dot) de) -Paul Chakravarti: - * Initial implementation of the XTEA algorithm for Python. +Paul Chakravarti +---------------- -Christian Heimes: - * PEP 272 conform implementation using the original crypt(), xtea_decrypt() - and xtea_encrypt() functions from Paul Chakravarti. +Initial implementation of the XTEA algorithm for Python. - * Pyrex/C optimization written based on the wikipedia entry - http://en.wikipedia.org/wiki/XTEA +Christian Heimes +---------------- - * setup.py, Makefile and eggification +PEP 272 conform implementation using the original crypt(), xtea_decrypt() +and xtea_encrypt() functions from Paul Chakravarti. +Pyrex/C optimization written based on the wikipedia entry +http://en.wikipedia.org/wiki/XTEA - - - +setup.py, Makefile and eggification Added: xtea/trunk/src/xtea/tests.py =================================================================== --- xtea/trunk/src/xtea/tests.py (rev 0) +++ xtea/trunk/src/xtea/tests.py 2007-03-01 17:33:31 UTC (rev 221) @@ -0,0 +1,38 @@ +# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> +"""xtea unit tests +""" +__author__ = "Christian Heimes" +__version__ = "$Id: tests.py 216 2007-02-28 12:06:48Z tiran $" +__revision__ = "$Revision: 216 $" + +import os +import unittest +from doctest import DocTestSuite + +# make sure it's the module and not the package +from xtea import HOST_ENDIAN + +class CXteaTestCase(unittest.TestCase): + def setUp(self): + pass + + def tearDown(self): + pass + +class PyXteaTestCase(unittest.TestCase): + def setUp(self): + pass + + def tearDown(self): + pass + +def test_suite(): + return unittest.TestSuite(( + unittest.makeSuite(CXteaTestCase), + unittest.makeSuite(PyXteaTestCase), + DocTestSuite('xtea'), + )) + +if __name__ == '__main__': + unittest.main(defaultTest="test_suite") + Property changes on: xtea/trunk/src/xtea/tests.py ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-03-04 02:38:37
|
Revision: 227 http://pymoul.svn.sourceforge.net/pymoul/?rev=227&view=rev Author: tiran Date: 2007-03-03 18:38:37 -0800 (Sat, 03 Mar 2007) Log Message: ----------- Renamed some files Modified Paths: -------------- xtea/trunk/setup.py xtea/trunk/src/xtea/tea.py xtea/trunk/src/xtea/xtea.py xtea/trunk/src/xtea/xxtea.py Added Paths: ----------- xtea/trunk/src/xtea/_pyxtea.c xtea/trunk/src/xtea/_pyxtea.pyx xtea/trunk/src/xtea/ctea.c xtea/trunk/src/xtea/ctea.h Removed Paths: ------------- xtea/trunk/src/xtea/_xtea.c xtea/trunk/src/xtea/_xtea.pyx xtea/trunk/src/xtea/cxtea.c xtea/trunk/src/xtea/cxtea.h Modified: xtea/trunk/setup.py =================================================================== --- xtea/trunk/setup.py 2007-03-04 02:21:04 UTC (rev 226) +++ xtea/trunk/setup.py 2007-03-04 02:38:37 UTC (rev 227) @@ -38,7 +38,7 @@ me = "Christian Heimes" email = "chr...@ch..." -cxtea = Extension('xtea._xtea', ['src/xtea/_xtea.pyx', 'src/xtea/cxtea.c']) +cxtea = Extension('xtea._pyxtea', ['src/xtea/_pyxtea.pyx', 'src/xtea/ctea.c']) ext_modules = [] if os.name == 'posix': ext_modules.append(cxtea) Copied: xtea/trunk/src/xtea/_pyxtea.c (from rev 226, xtea/trunk/src/xtea/_xtea.c) =================================================================== --- xtea/trunk/src/xtea/_pyxtea.c (rev 0) +++ xtea/trunk/src/xtea/_pyxtea.c 2007-03-04 02:38:37 UTC (rev 227) @@ -0,0 +1,1002 @@ +/* Generated by Pyrex 0.9.5.1a on Sun Mar 4 03:32:36 2007 */ + +#include "Python.h" +#include "structmember.h" +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif +#ifdef __cplusplus +#define __PYX_EXTERN_C extern "C" +#else +#define __PYX_EXTERN_C extern +#endif +__PYX_EXTERN_C double pow(double, double); +#include "stdlib.h" +#include "ctea.h" + + +typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/ +typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/ + +static PyObject *__pyx_m; +static PyObject *__pyx_b; +static int __pyx_lineno; +static char *__pyx_filename; +static char **__pyx_f; + +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ + +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ + +static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/ + +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ + +static void __Pyx_AddTraceback(char *funcname); /*proto*/ + +/* Declarations from _pyxtea */ + + + +/* Implementation of _pyxtea */ + +static PyObject *__pyx_n__c_tea_encrypt; +static PyObject *__pyx_n__c_tea_decrypt; +static PyObject *__pyx_n__c_xtea_encrypt; +static PyObject *__pyx_n__c_xtea_decrypt; +static PyObject *__pyx_n__c_xxtea_encrypt; +static PyObject *__pyx_n__c_xxtea_decrypt; + +static PyObject *__pyx_f_7_pyxtea__c_tea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_7_pyxtea__c_tea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_block = 0; + PyObject *__pyx_v_key = 0; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_v[2]); + unsigned long (__pyx_v_k[4]); + PyObject *__pyx_v_rc; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + unsigned long __pyx_3; + PyObject *__pyx_4 = 0; + static char *__pyx_argnames[] = {"block","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_block); + Py_INCREF(__pyx_v_key); + __pyx_v_rc = Py_None; Py_INCREF(Py_None); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":29 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[0]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":29 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[1]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":30 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[0]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":30 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[1]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":30 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[2]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":30 */ + __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[3]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":31 */ + __pyx_1 = PyInt_FromLong(tea_encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; goto __pyx_L1;} + Py_DECREF(__pyx_v_rc); + __pyx_v_rc = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":32 */ + __pyx_2 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + __pyx_4 = PyList_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_4, 0, __pyx_2); + PyList_SET_ITEM(__pyx_4, 1, __pyx_1); + __pyx_2 = 0; + __pyx_1 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_4; + __pyx_4 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":33 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_4); + __Pyx_AddTraceback("_pyxtea._c_tea_encrypt"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_rc); + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_block); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + +static PyObject *__pyx_f_7_pyxtea__c_tea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_7_pyxtea__c_tea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_block = 0; + PyObject *__pyx_v_key = 0; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_v[2]); + unsigned long (__pyx_v_k[4]); + PyObject *__pyx_v_rc; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + unsigned long __pyx_3; + PyObject *__pyx_4 = 0; + static char *__pyx_argnames[] = {"block","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_block); + Py_INCREF(__pyx_v_key); + __pyx_v_rc = Py_None; Py_INCREF(Py_None); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":38 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[0]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":38 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[1]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":39 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[0]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":39 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[1]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":39 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[2]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":39 */ + __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[3]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":40 */ + __pyx_1 = PyInt_FromLong(tea_decipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; goto __pyx_L1;} + Py_DECREF(__pyx_v_rc); + __pyx_v_rc = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":41 */ + __pyx_2 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; goto __pyx_L1;} + __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; goto __pyx_L1;} + __pyx_4 = PyList_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_4, 0, __pyx_2); + PyList_SET_ITEM(__pyx_4, 1, __pyx_1); + __pyx_2 = 0; + __pyx_1 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_4; + __pyx_4 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":42 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_4); + __Pyx_AddTraceback("_pyxtea._c_tea_decrypt"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_rc); + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_block); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + +static PyObject *__pyx_f_7_pyxtea__c_xtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_7_pyxtea__c_xtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_block = 0; + PyObject *__pyx_v_key = 0; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_v[2]); + unsigned long (__pyx_v_k[4]); + PyObject *__pyx_v_rc; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + unsigned long __pyx_3; + PyObject *__pyx_4 = 0; + static char *__pyx_argnames[] = {"block","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_block); + Py_INCREF(__pyx_v_key); + __pyx_v_rc = Py_None; Py_INCREF(Py_None); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":49 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[0]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":49 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[1]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":50 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[0]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":50 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[1]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":50 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[2]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":50 */ + __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[3]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":51 */ + __pyx_1 = PyInt_FromLong(xtea_encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; goto __pyx_L1;} + Py_DECREF(__pyx_v_rc); + __pyx_v_rc = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":52 */ + __pyx_2 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} + __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} + __pyx_4 = PyList_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_4, 0, __pyx_2); + PyList_SET_ITEM(__pyx_4, 1, __pyx_1); + __pyx_2 = 0; + __pyx_1 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_4; + __pyx_4 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":53 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_4); + __Pyx_AddTraceback("_pyxtea._c_xtea_encrypt"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_rc); + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_block); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + +static PyObject *__pyx_f_7_pyxtea__c_xtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_7_pyxtea__c_xtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_block = 0; + PyObject *__pyx_v_key = 0; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_v[2]); + unsigned long (__pyx_v_k[4]); + PyObject *__pyx_v_rc; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + unsigned long __pyx_3; + PyObject *__pyx_4 = 0; + static char *__pyx_argnames[] = {"block","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_block); + Py_INCREF(__pyx_v_key); + __pyx_v_rc = Py_None; Py_INCREF(Py_None); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":58 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[0]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":58 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[1]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":59 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[0]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":59 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[1]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":59 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[2]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":59 */ + __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[3]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":60 */ + __pyx_1 = PyInt_FromLong(xtea_decipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; goto __pyx_L1;} + Py_DECREF(__pyx_v_rc); + __pyx_v_rc = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":61 */ + __pyx_2 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; goto __pyx_L1;} + __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; goto __pyx_L1;} + __pyx_4 = PyList_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_4, 0, __pyx_2); + PyList_SET_ITEM(__pyx_4, 1, __pyx_1); + __pyx_2 = 0; + __pyx_1 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_4; + __pyx_4 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":62 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_4); + __Pyx_AddTraceback("_pyxtea._c_xtea_decrypt"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_rc); + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_block); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + +static PyObject *__pyx_n_len; +static PyObject *__pyx_n_ValueError; +static PyObject *__pyx_n_append; + +static PyObject *__pyx_k1p; + +static char (__pyx_k1[]) = "len(block) %i != rounds %i"; + +static PyObject *__pyx_f_7_pyxtea__c_xxtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_7_pyxtea__c_xxtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_block = 0; + PyObject *__pyx_v_key = 0; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_k[4]); + unsigned long (*__pyx_v_v); + int __pyx_v_rc; + int __pyx_v_size; + int __pyx_v_i; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + PyObject *__pyx_3 = 0; + int __pyx_4; + PyObject *__pyx_5 = 0; + unsigned long __pyx_6; + static char *__pyx_argnames[] = {"block","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_block); + Py_INCREF(__pyx_v_key); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":69 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;} + __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;} + Py_INCREF(__pyx_v_block); + PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_block); + __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_2); __pyx_2 = 0; + __pyx_4 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_v_size = __pyx_4; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":70 */ + __pyx_4 = (__pyx_v_size != __pyx_v_rounds); + if (__pyx_4) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":71 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; goto __pyx_L1;} + __pyx_2 = PyInt_FromLong(__pyx_v_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_rounds); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; goto __pyx_L1;} + __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_5, 0, __pyx_2); + PyTuple_SET_ITEM(__pyx_5, 1, __pyx_3); + __pyx_2 = 0; + __pyx_3 = 0; + __pyx_2 = PyNumber_Remainder(__pyx_k1p, __pyx_5); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + __Pyx_Raise(__pyx_1, __pyx_2, 0); + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_2); __pyx_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; goto __pyx_L1;} + goto __pyx_L2; + } + __pyx_L2:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":72 */ + __pyx_v_v = ((unsigned long (*))malloc(((sizeof(unsigned long )) * __pyx_v_size))); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":73 */ + for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":74 */ + __pyx_3 = PyInt_FromLong(__pyx_v_i); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_block, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_v[__pyx_v_i]) = __pyx_6; + } + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":75 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[0]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":75 */ + __pyx_3 = PyInt_FromLong(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[1]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":75 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[2]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":75 */ + __pyx_3 = PyInt_FromLong(3); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[3]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":76 */ + __pyx_v_rc = xxtea_encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":77 */ + __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; goto __pyx_L1;} + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":78 */ + for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":79 */ + __pyx_2 = PyObject_GetAttr(__pyx_v_result, __pyx_n_append); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong((__pyx_v_v[__pyx_v_i])); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; goto __pyx_L1;} + __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_5, 0, __pyx_3); + __pyx_3 = 0; + __pyx_1 = PyObject_CallObject(__pyx_2, __pyx_5); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + Py_DECREF(__pyx_5); __pyx_5 = 0; + Py_DECREF(__pyx_1); __pyx_1 = 0; + } + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":80 */ + free(__pyx_v_v); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":81 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_3); + Py_XDECREF(__pyx_5); + __Pyx_AddTraceback("_pyxtea._c_xxtea_encrypt"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_block); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + +static PyObject *__pyx_k2p; + +static char (__pyx_k2[]) = "len(block) %i != rounds %i"; + +static PyObject *__pyx_f_7_pyxtea__c_xxtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_7_pyxtea__c_xxtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_block = 0; + PyObject *__pyx_v_key = 0; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_k[4]); + unsigned long (*__pyx_v_v); + int __pyx_v_rc; + int __pyx_v_size; + int __pyx_v_i; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + PyObject *__pyx_3 = 0; + int __pyx_4; + PyObject *__pyx_5 = 0; + unsigned long __pyx_6; + static char *__pyx_argnames[] = {"block","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_block); + Py_INCREF(__pyx_v_key); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":86 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; goto __pyx_L1;} + __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; goto __pyx_L1;} + Py_INCREF(__pyx_v_block); + PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_block); + __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_2); __pyx_2 = 0; + __pyx_4 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_v_size = __pyx_4; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":87 */ + __pyx_4 = (__pyx_v_size != __pyx_v_rounds); + if (__pyx_4) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":88 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; goto __pyx_L1;} + __pyx_2 = PyInt_FromLong(__pyx_v_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_rounds); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; goto __pyx_L1;} + __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_5, 0, __pyx_2); + PyTuple_SET_ITEM(__pyx_5, 1, __pyx_3); + __pyx_2 = 0; + __pyx_3 = 0; + __pyx_2 = PyNumber_Remainder(__pyx_k2p, __pyx_5); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + __Pyx_Raise(__pyx_1, __pyx_2, 0); + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_2); __pyx_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; goto __pyx_L1;} + goto __pyx_L2; + } + __pyx_L2:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":89 */ + __pyx_v_v = ((unsigned long (*))malloc(((sizeof(unsigned long )) * __pyx_v_size))); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":90 */ + for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":91 */ + __pyx_3 = PyInt_FromLong(__pyx_v_i); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_block, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_v[__pyx_v_i]) = __pyx_6; + } + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":92 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[0]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":92 */ + __pyx_3 = PyInt_FromLong(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[1]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":92 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[2]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":92 */ + __pyx_3 = PyInt_FromLong(3); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[3]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":93 */ + __pyx_v_rc = xxtea_decipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":94 */ + __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; goto __pyx_L1;} + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":95 */ + for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":96 */ + __pyx_2 = PyObject_GetAttr(__pyx_v_result, __pyx_n_append); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong((__pyx_v_v[__pyx_v_i])); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; goto __pyx_L1;} + __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_5, 0, __pyx_3); + __pyx_3 = 0; + __pyx_1 = PyObject_CallObject(__pyx_2, __pyx_5); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + Py_DECREF(__pyx_5); __pyx_5 = 0; + Py_DECREF(__pyx_1); __pyx_1 = 0; + } + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":97 */ + free(__pyx_v_v); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":98 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_3); + Py_XDECREF(__pyx_5); + __Pyx_AddTraceback("_pyxtea._c_xxtea_decrypt"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_block); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + +static __Pyx_InternTabEntry __pyx_intern_tab[] = { + {&__pyx_n_ValueError, "ValueError"}, + {&__pyx_n__c_tea_decrypt, "_c_tea_decrypt"}, + {&__pyx_n__c_tea_encrypt, "_c_tea_encrypt"}, + {&__pyx_n__c_xtea_decrypt, "_c_xtea_decrypt"}, + {&__pyx_n__c_xtea_encrypt, "_c_xtea_encrypt"}, + {&__pyx_n__c_xxtea_decrypt, "_c_xxtea_decrypt"}, + {&__pyx_n__c_xxtea_encrypt, "_c_xxtea_encrypt"}, + {&__pyx_n_append, "append"}, + {&__pyx_n_len, "len"}, + {0, 0} +}; + +static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_k1p, __pyx_k1, sizeof(__pyx_k1)}, + {&__pyx_k2p, __pyx_k2, sizeof(__pyx_k2)}, + {0, 0, 0} +}; + +static struct PyMethodDef __pyx_methods[] = { + {"_c_tea_encrypt", (PyCFunction)__pyx_f_7_pyxtea__c_tea_encrypt, METH_VARARGS|METH_KEYWORDS, 0}, + {"_c_tea_decrypt", (PyCFunction)__pyx_f_7_pyxtea__c_tea_decrypt, METH_VARARGS|METH_KEYWORDS, 0}, + {"_c_xtea_encrypt", (PyCFunction)__pyx_f_7_pyxtea__c_xtea_encrypt, METH_VARARGS|METH_KEYWORDS, 0}, + {"_c_xtea_decrypt", (PyCFunction)__pyx_f_7_pyxtea__c_xtea_decrypt, METH_VARARGS|METH_KEYWORDS, 0}, + {"_c_xxtea_encrypt", (PyCFunction)__pyx_f_7_pyxtea__c_xxtea_encrypt, METH_VARARGS|METH_KEYWORDS, 0}, + {"_c_xxtea_decrypt", (PyCFunction)__pyx_f_7_pyxtea__c_xxtea_decrypt, METH_VARARGS|METH_KEYWORDS, 0}, + {0, 0, 0, 0} +}; + +static void __pyx_init_filenames(void); /*proto*/ + +PyMODINIT_FUNC init_pyxtea(void); /*proto*/ +PyMODINIT_FUNC init_pyxtea(void) { + __pyx_init_filenames(); + __pyx_m = Py_InitModule4("_pyxtea", __pyx_methods, 0, 0, PYTHON_API_VERSION); + if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}; + __pyx_b = PyImport_AddModule("__builtin__"); + if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}; + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}; + if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}; + if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":83 */ + return; + __pyx_L1:; + __Pyx_AddTraceback("_pyxtea"); +} + +static char *__pyx_filenames[] = { + "_pyxtea.pyx", +}; + +/* Runtime support code */ + +static void __pyx_init_filenames(void) { + __pyx_f = __pyx_filenames; +} + +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { + PyObject *result; + result = PyObject_GetAttr(dict, name); + if (!result) + PyErr_SetObject(PyExc_NameError, name); + return result; +} + +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) { + Py_XINCREF(type); + Py_XINCREF(value); + Py_XINCREF(tb); + /* First, check the traceback argument, replacing None with NULL. */ + if (tb == Py_None) { + Py_DECREF(tb); + tb = 0; + } + else if (tb != NULL && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto raise_error; + } + /* Next, replace a missing value with None */ + if (value == NULL) { + value = Py_None; + Py_INCREF(value); + } + /* Next, repeatedly, replace a tuple exception with its first item */ + while (PyTuple_Check(type) && PyTuple_Size(type) > 0) { + PyObject *tmp = type; + type = PyTuple_GET_ITEM(type, 0); + Py_INCREF(type); + Py_DECREF(tmp); + } + if (PyString_Check(type)) { + if (PyErr_Warn(PyExc_DeprecationWarning, + "raising a string exception is deprecated")) + goto raise_error; + } + else if (PyType_Check(type) || PyClass_Check(type)) + ; /*PyErr_NormalizeException(&type, &value, &tb);*/ + else { + /* Raising an instance. The value should be a dummy. */ + if (value != Py_None) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto raise_error; + } + /* Normalize to raise <class>, <instance> */ + Py_DECREF(value); + value = type; + if (PyInstance_Check(type)) + type = (PyObject*) ((PyInstanceObject*)type)->in_class; + else + type = (PyObject*) type->ob_type; + Py_INCREF(type); + } + PyErr_Restore(type, value, tb); + return; +raise_error: + Py_XDECREF(value); + Py_XDECREF(type); + Py_XDECREF(tb); + return; +} + +static int __Pyx_InternStrings(__Pyx_InternTabEntry *t) { + while (t->p) { + *t->p = PyString_InternFromString(t->s); + if (!*t->p) + return -1; + ++t; + } + return 0; +} + +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + while (t->p) { + *t->p = PyString_FromStringAndSize(t->s, t->n - 1); + if (!*t->p) + return -1; + ++t; + } + return 0; +} + +#include "compile.h" +#include "frameobject.h" +#include "traceback.h" + +static void __Pyx_AddTraceback(char *funcname) { + PyObject *py_srcfile = 0; + PyObject *py_funcname = 0; + PyObject *py_globals = 0; + PyObject *empty_tuple = 0; + PyObject *empty_string = 0; + PyCodeObject *py_code = 0; + PyFrameObject *py_frame = 0; + + py_srcfile = PyString_FromString(__pyx_filename); + if (!py_srcfile) goto bad; + py_funcname = PyString_FromString(funcname); + if (!py_funcname) goto bad; + py_globals = PyModule_GetDict(__pyx_m); + if (!py_globals) goto bad; + empty_tuple = PyTuple_New(0); + if (!empty_tuple) goto bad; + empty_string = PyString_FromString(""); + if (!empty_string) goto bad; + py_code = PyCode_New( + 0, /*int argcount,*/ + 0, /*int nlocals,*/ + 0, /*int stacksize,*/ + 0, /*int flags,*/ + empty_string, /*PyObject *code,*/ + empty_tuple, /*PyObject *consts,*/ + empty_tuple, /*PyObject *names,*/ + empty_tuple, /*PyObject *varnames,*/ + empty_tuple, /*PyObject *freevars,*/ + empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + __pyx_lineno, /*int firstlineno,*/ + empty_string /*PyObject *lnotab*/ + ); + if (!py_code) goto bad; + py_frame = PyFrame_New( + PyThreadState_Get(), /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + py_globals, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + py_frame->f_lineno = __pyx_lineno; + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_srcfile); + Py_XDECREF(py_funcname); + Py_XDECREF(empty_tuple); + Py_XDECREF(empty_string); + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} Copied: xtea/trunk/src/xtea/_pyxtea.pyx (from rev 226, xtea/trunk/src/xtea/_xtea.pyx) =================================================================== --- xtea/trunk/src/xtea/_pyxtea.pyx (rev 0) +++ xtea/trunk/src/xtea/_pyxtea.pyx 2007-03-04 02:38:37 UTC (rev 227) @@ -0,0 +1,98 @@ +# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> +# pyrexc optimized version +# License: Public Domain + +# http://www.python.org/dev/peps/pep-0272/ + +ctypedef unsigned long ULong +ctypedef unsigned int UInt + +cdef extern from "stdlib.h": + ctypedef unsigned long size_t + void *malloc(size_t size) + void free(void* ptr) + size_t sizeof(void *) + +cdef extern from "ctea.h": + int tea_decipher(ULong *v, ULong *k, UInt n) + int tea_encipher(ULong *v, ULong *k, UInt n) + int xtea_decipher(ULong *v, ULong *k, UInt n) + int xtea_encipher(ULong *v, ULong *k, UInt n) + int xxtea_decipher(ULong *v, ULong *k, UInt n) + int xxtea_encipher(ULong *v, ULong *k, UInt n) + +# *** TEA *** + +def _c_tea_encrypt(object block, object key, UInt rounds): + cdef ULong v[2] + cdef ULong k[4] + v[0] = block[0]; v[1] = block[1] + k[0] = key[0]; k[1] = key[1]; k[2] = key[2]; k[3] = key[3] + rc = tea_encipher(v, k, rounds) + result = [v[0], v[1]] + return result + +def _c_tea_decrypt(object block, object key, UInt rounds): + cdef ULong v[2] + cdef ULong k[4] + v[0] = block[0]; v[1] = block[1] + k[0] = key[0]; k[1] = key[1]; k[2] = key[2]; k[3] = key[3] + rc = tea_decipher(v, k, rounds) + result = [v[0], v[1]] + return result + +# *** XTEA *** + +def _c_xtea_encrypt(object block, object key, UInt rounds): + cdef ULong v[2] + cdef ULong k[4] + v[0] = block[0]; v[1] = block[1] + k[0] = key[0]; k[1] = key[1]; k[2] = key[2]; k[3] = key[3] + rc = xtea_encipher(v, k, rounds) + result = [v[0], v[1]] + return result + +def _c_xtea_decrypt(object block, object key, UInt rounds): + cdef ULong v[2] + cdef ULong k[4] + v[0] = block[0]; v[1] = block[1] + k[0] = key[0]; k[1] = key[1]; k[2] = key[2]; k[3] = key[3] + rc = xtea_decipher(v, k, rounds) + result = [v[0], v[1]] + return result + +# *** XXTEA *** + +def _c_xxtea_encrypt(object block, key, UInt rounds): + cdef ULong k[4], *v + cdef int rc, size, i + size = len(block) + if size != rounds: + raise ValueError, "len(block) %i != rounds %i" % (size, rounds) + v = <ULong *>malloc(sizeof(ULong) * size) + for i from 0 <= i < size: + v[i] = block[i] + k[0] = key[0]; k[1] = key[1]; k[2] = key[2]; k[3] = key[3] + rc = xxtea_encipher(v, k, rounds) + result = [] + for i from 0 <= i < size: + result.append(v[i]) + free(v) + return result + +def _c_xxtea_decrypt(object block, key, UInt rounds): + cdef ULong k[4], *v + cdef int rc, size, i + size = len(block) + if size != rounds: + raise ValueError, "len(block) %i != rounds %i" % (size, rounds) + v = <ULong *>malloc(sizeof(ULong) * size) + for i from 0 <= i < size: + v[i] = block[i] + k[0] = key[0]; k[1] = key[1]; k[2] = key[2]; k[3] = key[3] + rc = xxtea_decipher(v, k, rounds) + result = [] + for i from 0 <= i < size: + result.append(v[i]) + free(v) + return result Deleted: xtea/trunk/src/xtea/_xtea.c =================================================================== --- xtea/trunk/src/xtea/_xtea.c 2007-03-04 02:21:04 UTC (rev 226) +++ xtea/trunk/src/xtea/_xtea.c 2007-03-04 02:38:37 UTC (rev 227) @@ -1,1002 +0,0 @@ -/* Generated by Pyrex 0.9.5.1a on Sun Mar 4 03:00:20 2007 */ - -#include "Python.h" -#include "structmember.h" -#ifndef PY_LONG_LONG - #define PY_LONG_LONG LONG_LONG -#endif -#ifdef __cplusplus -#define __PYX_EXTERN_C extern "C" -#else -#define __PYX_EXTERN_C extern -#endif -__PYX_EXTERN_C double pow(double, double); -#include "stdlib.h" -#include "cxtea.h" - - -typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/ -typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/ - -static PyObject *__pyx_m; -static PyObject *__pyx_b; -static int __pyx_lineno; -static char *__pyx_filename; -static char **__pyx_f; - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ - -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ - -static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/ - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ - -static void __Pyx_AddTraceback(char *funcname); /*proto*/ - -/* Declarations from _xtea */ - - - -/* Implementation of _xtea */ - -static PyObject *__pyx_n__c_tea_encrypt; -static PyObject *__pyx_n__c_tea_decrypt; -static PyObject *__pyx_n__c_xtea_encrypt; -static PyObject *__pyx_n__c_xtea_decrypt; -static PyObject *__pyx_n__c_xxtea_encrypt; -static PyObject *__pyx_n__c_xxtea_decrypt; - -static PyObject *__pyx_f_5_xtea__c_tea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_f_5_xtea__c_tea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_block = 0; - PyObject *__pyx_v_key = 0; - unsigned int __pyx_v_rounds; - unsigned long (__pyx_v_v[2]); - unsigned long (__pyx_v_k[4]); - PyObject *__pyx_v_rc; - PyObject *__pyx_v_result; - PyObject *__pyx_r; - PyObject *__pyx_1 = 0; - PyObject *__pyx_2 = 0; - unsigned long __pyx_3; - PyObject *__pyx_4 = 0; - static char *__pyx_argnames[] = {"block","key","rounds",0}; - if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; - Py_INCREF(__pyx_v_block); - Py_INCREF(__pyx_v_key); - __pyx_v_rc = Py_None; Py_INCREF(Py_None); - __pyx_v_result = Py_None; Py_INCREF(Py_None); - - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":29 */ - __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - (__pyx_v_v[0]) = __pyx_3; - - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":29 */ - __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - (__pyx_v_v[1]) = __pyx_3; - - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":30 */ - __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - (__pyx_v_k[0]) = __pyx_3; - - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":30 */ - __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - (__pyx_v_k[1]) = __pyx_3; - - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":30 */ - __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - (__pyx_v_k[2]) = __pyx_3; - - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":30 */ - __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - (__pyx_v_k[3]) = __pyx_3; - - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":31 */ - __pyx_1 = PyInt_FromLong(tea_encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; goto __pyx_L1;} - Py_DECREF(__pyx_v_rc); - __pyx_v_rc = __pyx_1; - __pyx_1 = 0; - - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":32 */ - __pyx_2 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - __pyx_4 = PyList_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - PyList_SET_ITEM(__pyx_4, 0, __pyx_2); - PyList_SET_ITEM(__pyx_4, 1, __pyx_1); - __pyx_2 = 0; - __pyx_1 = 0; - Py_DECREF(__pyx_v_result); - __pyx_v_result = __pyx_4; - __pyx_4 = 0; - - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":33 */ - Py_INCREF(__pyx_v_result); - __pyx_r = __pyx_v_result; - goto __pyx_L0; - - __pyx_r = Py_None; Py_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1:; - Py_XDECREF(__pyx_1); - Py_XDECREF(__pyx_2); - Py_XDECREF(__pyx_4); - __Pyx_AddTraceback("_xtea._c_tea_encrypt"); - __pyx_r = 0; - __pyx_L0:; - Py_DECREF(__pyx_v_rc); - Py_DECREF(__pyx_v_result); - Py_DECREF(__pyx_v_block); - Py_DECREF(__pyx_v_key); - return __pyx_r; -} - -static PyObject *__pyx_f_5_xtea__c_tea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_f_5_xtea__c_tea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_block = 0; - PyObject *__pyx_v_key = 0; - unsigned int __pyx_v_rounds; - unsigned long (__pyx_v_v[2]); - unsigned long (__pyx_v_k[4]); - PyObject *__pyx_v_rc; - PyObject *__pyx_v_result; - PyObject *__pyx_r; - PyObject *__pyx_1 = 0; - PyObject *__pyx_2 = 0; - unsigned long __pyx_3; - PyObject *__pyx_4 = 0; - static char *__pyx_argnames[] = {"block","key","rounds",0}; - if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; - Py_INCREF(__pyx_v_block); - Py_INCREF(__pyx_v_key); - __pyx_v_rc = Py_None; Py_INCREF(Py_None); - __pyx_v_result = Py_None; Py_INCREF(Py_None); - - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":38 */ - __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - (__pyx_v_v[0]) = __pyx_3; - - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":38 */ - __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx... [truncated message content] |
From: <ti...@us...> - 2007-03-04 02:44:32
|
Revision: 228 http://pymoul.svn.sourceforge.net/pymoul/?rev=228&view=rev Author: tiran Date: 2007-03-03 18:44:33 -0800 (Sat, 03 Mar 2007) Log Message: ----------- Renamed package and files Modified Paths: -------------- xtea/trunk/Makefile xtea/trunk/setup.py Added Paths: ----------- xtea/trunk/src/crypttea/ xtea/trunk/src/crypttea/__init__.py xtea/trunk/src/crypttea/_common.py xtea/trunk/src/crypttea/_pyxtea.c xtea/trunk/src/crypttea/_pyxtea.pyx xtea/trunk/src/crypttea/ctea.c xtea/trunk/src/crypttea/ctea.h xtea/trunk/src/crypttea/tea.py xtea/trunk/src/crypttea/tests.py xtea/trunk/src/crypttea/xtea.py xtea/trunk/src/crypttea/xxtea.py xtea/trunk/src/crypttea.egg-info/ xtea/trunk/src/crypttea.egg-info/PKG-INFO xtea/trunk/src/crypttea.egg-info/SOURCES.txt xtea/trunk/src/crypttea.egg-info/dependency_links.txt xtea/trunk/src/crypttea.egg-info/native_libs.txt xtea/trunk/src/crypttea.egg-info/top_level.txt xtea/trunk/src/crypttea.egg-info/zip-safe Removed Paths: ------------- xtea/trunk/src/crypttea/__init__.py xtea/trunk/src/crypttea/_common.py xtea/trunk/src/crypttea/_xtea.c xtea/trunk/src/crypttea/_xtea.pyx xtea/trunk/src/crypttea/cxtea.c xtea/trunk/src/crypttea/cxtea.h xtea/trunk/src/crypttea/tea.py xtea/trunk/src/crypttea/tests.py xtea/trunk/src/crypttea/xtea.py xtea/trunk/src/crypttea/xxtea.py xtea/trunk/src/crypttea.egg-info/PKG-INFO xtea/trunk/src/crypttea.egg-info/SOURCES.txt xtea/trunk/src/crypttea.egg-info/dependency_links.txt xtea/trunk/src/crypttea.egg-info/native_libs.txt xtea/trunk/src/crypttea.egg-info/top_level.txt xtea/trunk/src/crypttea.egg-info/zip-safe xtea/trunk/src/xtea/ xtea/trunk/src/xtea.egg-info/ Modified: xtea/trunk/Makefile =================================================================== --- xtea/trunk/Makefile 2007-03-04 02:38:37 UTC (rev 227) +++ xtea/trunk/Makefile 2007-03-04 02:44:33 UTC (rev 228) @@ -32,7 +32,7 @@ # What should the default be? test: - PYTHONPATH=src $(PYTHON) src/xtea/tests.py + PYTHONPATH=src $(PYTHON) src/crypttea/tests.py egg: egg24 egg25 @@ -52,3 +52,4 @@ rm -f TAGS rm -rf dist $(PYTHON) setup.py clean -a + Modified: xtea/trunk/setup.py =================================================================== --- xtea/trunk/setup.py 2007-03-04 02:38:37 UTC (rev 227) +++ xtea/trunk/setup.py 2007-03-04 02:44:33 UTC (rev 228) @@ -1,15 +1,7 @@ #!/usr/bin/env python -"""XTEA Block Encryption Algorithm +"""TEA, XTEA and XXTEA Block Encryption Algorithms -This module provides a Python implementation of the XTEA block encryption -algorithm (http://www.cix.co.uk/~klockstone/xtea.pdf). - -The module implements the basic XTEA block encryption algortithm -(`xtea_encrypt`/`xtea_decrypt`) and also provides a higher level `crypt` -function which symmetrically encrypts/decrypts a variable length string using -XTEA in OFB mode as a key generator. The `crypt` function does not use -`xtea_decrypt` which is provided for completeness only (but can be used -to support other stream modes - eg CBC/CFB). +TODO """ __author__ = "Christian Heimes" __version__ = "$Id: setup.py 203 2007-02-27 14:31:27Z tiran $" @@ -38,25 +30,28 @@ me = "Christian Heimes" email = "chr...@ch..." -cxtea = Extension('xtea._pyxtea', ['src/xtea/_pyxtea.pyx', 'src/xtea/ctea.c']) +cxtea = Extension('crypttea._pyxtea', + ['src/crypttea/_pyxtea.pyx', 'src/crypttea/ctea.c'] + ) ext_modules = [] if os.name == 'posix': ext_modules.append(cxtea) setup_infos = dict( - name = "xtea", + name = "crypttea", version = VERSION, description = __doc__[:__doc__.find('\n')].strip(), long_description = '\n'.join([line for line in __doc__.split('\n')[1:]]), - author = "Paul Chakravarti", - author_email = "paul_dot_chakravarti_at_mac_dot_com", + author = "Christian Heimes", + author_email = "chr...@ch...", maintainer = "Christian Heimes", maintainer_email = "chr...@ch...", url = "http://sourceforge.net/projects/pymoul/", download_url= "http://cheeseshop.python.org/pypi/", license = "Public Domain", - keywords = ["xtea", "crypt", "encryption", "decryption"], + keywords = ["xtea", "tea", "xxtea", "btea", "crypt", + "encryption", "decryption", "cipher", "crypto"], platforms = ['Independent'], classifiers = ( #'Development Status :: 6 - Mature', @@ -70,9 +65,10 @@ ), ext_modules=ext_modules, setup_requires = ["setuptools>="+SETUPTOOLS_VERSION,], - packages = ['xtea'], + packages = ['crypttea'], package_dir = {'' : 'src'}, zip_safe = True, ) setup(**setup_infos) + Copied: xtea/trunk/src/crypttea (from rev 226, xtea/trunk/src/xtea) Property changes on: xtea/trunk/src/crypttea ___________________________________________________________________ Name: svn:ignore + _pyxtea.so Deleted: xtea/trunk/src/crypttea/__init__.py =================================================================== --- xtea/trunk/src/xtea/__init__.py 2007-03-04 02:21:04 UTC (rev 226) +++ xtea/trunk/src/crypttea/__init__.py 2007-03-04 02:44:33 UTC (rev 228) @@ -1,12 +0,0 @@ -# xtea package -#from tea import TEA -from xtea import XTEA -#from xxtea import XXTEA - -from _common import MODE_ECB -from _common import MODE_OFB -from _common import BIG_ENDIAN -from _common import LITTLE_ENDIAN -from _common import NETWORK_ENDIAN -from _common import HOST_ENDIAN -from _common import pad Copied: xtea/trunk/src/crypttea/__init__.py (from rev 227, xtea/trunk/src/xtea/__init__.py) =================================================================== --- xtea/trunk/src/crypttea/__init__.py (rev 0) +++ xtea/trunk/src/crypttea/__init__.py 2007-03-04 02:44:33 UTC (rev 228) @@ -0,0 +1,12 @@ +# xtea package +#from tea import TEA +from xtea import XTEA +#from xxtea import XXTEA + +from _common import MODE_ECB +from _common import MODE_OFB +from _common import BIG_ENDIAN +from _common import LITTLE_ENDIAN +from _common import NETWORK_ENDIAN +from _common import HOST_ENDIAN +from _common import pad Deleted: xtea/trunk/src/crypttea/_common.py =================================================================== --- xtea/trunk/src/xtea/_common.py 2007-03-04 02:21:04 UTC (rev 226) +++ xtea/trunk/src/crypttea/_common.py 2007-03-04 02:44:33 UTC (rev 228) @@ -1,213 +0,0 @@ -""" -""" -from struct import pack -from struct import unpack -import sys - -__all__ = ['MODE_ECB', 'MODE_OFB', 'BIG_ENDIAN', 'LITTLE_ENDIAN', - 'NETWORK_ENDIAN', 'HOST_ENDIAN', 'pad'] - -MODE_ECB = 1 # Electronic Code Book -MODE_CBC = 2 # Cipher Block Chaining -MODE_CFB = 4 # Cipher Feedback -MODE_OFB = 5 # Output Feedback -MODE_CTR = 6 # Counter - -BIG_ENDIAN = 'big' -LITTLE_ENDIAN = 'little' -NETWORK_ENDIAN = LITTLE_ENDIAN -HOST_ENDIAN = sys.byteorder - -NULL='\x00' -ULONG_SIZE=4 -DELTA=0x9E3779B9 - -def pad(s, align, char=NULL): - """Pad string 's' to 'align' number of elements with char 'char' - - >>> pad('abcd', 4) - 'abcd' - >>> pad('abcdabcd', 4) - 'abcdabcd' - >>> pad('abcdef', 4) - 'abcdef\\x00\\x00' - >>> pad('abcdef', 4, char='0') - 'abcdef00' - """ - mod = len(s) % align - if mod != 0: - return s+mod*char - else: - return s - -class _AbstractTEA(object): - """Abstract TEA base class - """ - @property - def key_size(self): - """Size of key - """ - return 16 - - @property - def block_size(self): - """Size of blocks - """ - return 8 - - @property - def default_rounds(self): - """Default number of rounds - """ - return 32 - - def __init__(self, key, mode=MODE_ECB, IV=8*NULL, rounds=None, - endian=HOST_ENDIAN, counter=None, segment_size=None): - if endian == BIG_ENDIAN: - self._endian = ">" - elif endian == LITTLE_ENDIAN: - self._endian = "<" - else: - raise ValueError("Unknown endian: %s" % endian) - - ks = self.key_size - if isinstance(key, tuple): - if len(key) != ks/ULONG_SIZE: - raise ValueError("Invalid key size") - for e in key: - if not isinstance(e, (long, int)): - raise TypeError("Wrong type %s in key" % repr(e)) - self._key = key - elif isinstance(key, str): - if len(key) != ks: - raise ValueError("Invalid key size") - self._key = unpack("%s%iL" % (self._endian, ks/ULONG_SIZE), key) - else: - raise TypeError("Invalid key type") - - if mode == MODE_ECB: - pass - elif mode == MODE_OFB: - if not isinstance(IV, str) or len(IV) != self.block_size: - raise ValueError("Invalid IV") - else: - raise ValueError("Unknown or unsupported mode") - self._mode = mode - self._iv = IV - - if rounds is None: - rounds = self.default_rounds - if rounds < 2 or not isinstance(rounds, int): - raise ValueError("Invalid rounds") - self._rounds = rounds - self._counter = counter - self._segment_size = segment_size - - @classmethod - def new(cls, key, **kwargs): - """PEP 272 conform constructor - """ - return cls(key, **kwargs) - - @classmethod - def setDefaultImpl(cls, impl='py'): - """Set default implementation - """ - if impl == 'py': - cls._decrypt = staticmethod(cls._py_decrypt) - cls._encrypt = staticmethod(cls._py_encrypt) - elif impl == 'c': - assert cls._c_decrypt is not None - cls._decrypt = cls._c_decrypt - cls._encrypt = cls._c_encrypt - else: - raise ValueError(impl) - - def setImpl(self, impl='py'): - """Set implementation for this instance - """ - if impl == 'py': - self._decrypt = staticmethod(self._py_decrypt) - self._encrypt = staticmethod(self._py_encrypt) - elif impl == 'c': - assert self._c_decrypt is not None - self._decrypt = self._c_decrypt - self._encrypt = self._c_encrypt - else: - raise ValueError(impl) - - def encrypt(self, block): - """Encrypt a block - - @param block: block to encrypt - @type block: str - """ - if self._mode == MODE_ECB: - return self._ecb(block, func=self._encrypt) - elif self._mode == MODE_OFB: - return self._ofb(block) - else: - raise ValueError("Unknown or unsupported mode") - - def decrypt(self, block): - """Decrypt a block - - @param block: block to decrypt - @type block: str - """ - if self._mode == MODE_ECB: - return self._ecb(block, func=self._decrypt) - elif self._mode == MODE_OFB: - return self._ofb(block) - else: - raise ValueError("Unknown or unsupported mode") - - _decrypt = None - _encrypt = None - _c_decrypt = None - _c_encrypt = None - _py_decrypt = None - _py_encrypt = None - - def _ecb(self, block, func): - """Electronic Code Book encryption/decryption - - @type block: str - @param func: decrypt or encrypt function - @type func: callable(v0, v1, keys[4], rounds) - """ - l = len(block) - bs = self.block_size - key, rounds = self._key, self._rounds - fmt = self._endian+"2L" - result = [] - if l % bs != 0: - raise ValueError - for i in range(l/bs): - v = unpack(fmt, block[i*bs:(i+1)*bs]) - w = func(v, key, rounds) - result.append(pack(fmt, *w)) - return ''.join(result) - - def _ofb_keygen(self): - """Key generator - - @return: generator function - """ - key, iv, rounds = self._key, self._iv, self._rounds - fmt = self._endian+"%iL" % (self.block_size/ULONG_SIZE) - #v0, v1 = unpack(self._endian+"2L", iv) - while True: - v = unpack(fmt, iv) - w = self._encrypt(v, key, rounds) - iv = pack(fmt, *w) - for k in iv: - yield ord(k) - - def _ofb(self, block): - """Output Feedback (OFB) encryption requires an IV - """ - key = pack(self._endian+"%iL" % (self.key_size/ULONG_SIZE), *self._key) - gen = self._ofb_keygen() - xor = [chr(x^y) for (x, y) in zip(map(ord, block), gen)] - return ''.join(xor) Copied: xtea/trunk/src/crypttea/_common.py (from rev 227, xtea/trunk/src/xtea/_common.py) =================================================================== --- xtea/trunk/src/crypttea/_common.py (rev 0) +++ xtea/trunk/src/crypttea/_common.py 2007-03-04 02:44:33 UTC (rev 228) @@ -0,0 +1,213 @@ +""" +""" +from struct import pack +from struct import unpack +import sys + +__all__ = ['MODE_ECB', 'MODE_OFB', 'BIG_ENDIAN', 'LITTLE_ENDIAN', + 'NETWORK_ENDIAN', 'HOST_ENDIAN', 'pad'] + +MODE_ECB = 1 # Electronic Code Book +MODE_CBC = 2 # Cipher Block Chaining +MODE_CFB = 4 # Cipher Feedback +MODE_OFB = 5 # Output Feedback +MODE_CTR = 6 # Counter + +BIG_ENDIAN = 'big' +LITTLE_ENDIAN = 'little' +NETWORK_ENDIAN = LITTLE_ENDIAN +HOST_ENDIAN = sys.byteorder + +NULL='\x00' +ULONG_SIZE=4 +DELTA=0x9E3779B9 + +def pad(s, align, char=NULL): + """Pad string 's' to 'align' number of elements with char 'char' + + >>> pad('abcd', 4) + 'abcd' + >>> pad('abcdabcd', 4) + 'abcdabcd' + >>> pad('abcdef', 4) + 'abcdef\\x00\\x00' + >>> pad('abcdef', 4, char='0') + 'abcdef00' + """ + mod = len(s) % align + if mod != 0: + return s+mod*char + else: + return s + +class _AbstractTEA(object): + """Abstract TEA base class + """ + @property + def key_size(self): + """Size of key + """ + return 16 + + @property + def block_size(self): + """Size of blocks + """ + return 8 + + @property + def default_rounds(self): + """Default number of rounds + """ + return 32 + + def __init__(self, key, mode=MODE_ECB, IV=8*NULL, rounds=None, + endian=HOST_ENDIAN, counter=None, segment_size=None): + if endian == BIG_ENDIAN: + self._endian = ">" + elif endian == LITTLE_ENDIAN: + self._endian = "<" + else: + raise ValueError("Unknown endian: %s" % endian) + + ks = self.key_size + if isinstance(key, tuple): + if len(key) != ks/ULONG_SIZE: + raise ValueError("Invalid key size") + for e in key: + if not isinstance(e, (long, int)): + raise TypeError("Wrong type %s in key" % repr(e)) + self._key = key + elif isinstance(key, str): + if len(key) != ks: + raise ValueError("Invalid key size") + self._key = unpack("%s%iL" % (self._endian, ks/ULONG_SIZE), key) + else: + raise TypeError("Invalid key type") + + if mode == MODE_ECB: + pass + elif mode == MODE_OFB: + if not isinstance(IV, str) or len(IV) != self.block_size: + raise ValueError("Invalid IV") + else: + raise ValueError("Unknown or unsupported mode") + self._mode = mode + self._iv = IV + + if rounds is None: + rounds = self.default_rounds + if rounds < 2 or not isinstance(rounds, int): + raise ValueError("Invalid rounds") + self._rounds = rounds + self._counter = counter + self._segment_size = segment_size + + @classmethod + def new(cls, key, **kwargs): + """PEP 272 conform constructor + """ + return cls(key, **kwargs) + + @classmethod + def setDefaultImpl(cls, impl='py'): + """Set default implementation + """ + if impl == 'py': + cls._decrypt = staticmethod(cls._py_decrypt) + cls._encrypt = staticmethod(cls._py_encrypt) + elif impl == 'c': + assert cls._c_decrypt is not None + cls._decrypt = cls._c_decrypt + cls._encrypt = cls._c_encrypt + else: + raise ValueError(impl) + + def setImpl(self, impl='py'): + """Set implementation for this instance + """ + if impl == 'py': + self._decrypt = staticmethod(self._py_decrypt) + self._encrypt = staticmethod(self._py_encrypt) + elif impl == 'c': + assert self._c_decrypt is not None + self._decrypt = self._c_decrypt + self._encrypt = self._c_encrypt + else: + raise ValueError(impl) + + def encrypt(self, block): + """Encrypt a block + + @param block: block to encrypt + @type block: str + """ + if self._mode == MODE_ECB: + return self._ecb(block, func=self._encrypt) + elif self._mode == MODE_OFB: + return self._ofb(block) + else: + raise ValueError("Unknown or unsupported mode") + + def decrypt(self, block): + """Decrypt a block + + @param block: block to decrypt + @type block: str + """ + if self._mode == MODE_ECB: + return self._ecb(block, func=self._decrypt) + elif self._mode == MODE_OFB: + return self._ofb(block) + else: + raise ValueError("Unknown or unsupported mode") + + _decrypt = None + _encrypt = None + _c_decrypt = None + _c_encrypt = None + _py_decrypt = None + _py_encrypt = None + + def _ecb(self, block, func): + """Electronic Code Book encryption/decryption + + @type block: str + @param func: decrypt or encrypt function + @type func: callable(v0, v1, keys[4], rounds) + """ + l = len(block) + bs = self.block_size + key, rounds = self._key, self._rounds + fmt = self._endian+"2L" + result = [] + if l % bs != 0: + raise ValueError + for i in range(l/bs): + v = unpack(fmt, block[i*bs:(i+1)*bs]) + w = func(v, key, rounds) + result.append(pack(fmt, *w)) + return ''.join(result) + + def _ofb_keygen(self): + """Key generator + + @return: generator function + """ + key, iv, rounds = self._key, self._iv, self._rounds + fmt = self._endian+"%iL" % (self.block_size/ULONG_SIZE) + #v0, v1 = unpack(self._endian+"2L", iv) + while True: + v = unpack(fmt, iv) + w = self._encrypt(v, key, rounds) + iv = pack(fmt, *w) + for k in iv: + yield ord(k) + + def _ofb(self, block): + """Output Feedback (OFB) encryption requires an IV + """ + key = pack(self._endian+"%iL" % (self.key_size/ULONG_SIZE), *self._key) + gen = self._ofb_keygen() + xor = [chr(x^y) for (x, y) in zip(map(ord, block), gen)] + return ''.join(xor) Copied: xtea/trunk/src/crypttea/_pyxtea.c (from rev 227, xtea/trunk/src/xtea/_pyxtea.c) =================================================================== --- xtea/trunk/src/crypttea/_pyxtea.c (rev 0) +++ xtea/trunk/src/crypttea/_pyxtea.c 2007-03-04 02:44:33 UTC (rev 228) @@ -0,0 +1,1002 @@ +/* Generated by Pyrex 0.9.5.1a on Sun Mar 4 03:32:36 2007 */ + +#include "Python.h" +#include "structmember.h" +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif +#ifdef __cplusplus +#define __PYX_EXTERN_C extern "C" +#else +#define __PYX_EXTERN_C extern +#endif +__PYX_EXTERN_C double pow(double, double); +#include "stdlib.h" +#include "ctea.h" + + +typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/ +typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/ + +static PyObject *__pyx_m; +static PyObject *__pyx_b; +static int __pyx_lineno; +static char *__pyx_filename; +static char **__pyx_f; + +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ + +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ + +static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/ + +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ + +static void __Pyx_AddTraceback(char *funcname); /*proto*/ + +/* Declarations from _pyxtea */ + + + +/* Implementation of _pyxtea */ + +static PyObject *__pyx_n__c_tea_encrypt; +static PyObject *__pyx_n__c_tea_decrypt; +static PyObject *__pyx_n__c_xtea_encrypt; +static PyObject *__pyx_n__c_xtea_decrypt; +static PyObject *__pyx_n__c_xxtea_encrypt; +static PyObject *__pyx_n__c_xxtea_decrypt; + +static PyObject *__pyx_f_7_pyxtea__c_tea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_7_pyxtea__c_tea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_block = 0; + PyObject *__pyx_v_key = 0; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_v[2]); + unsigned long (__pyx_v_k[4]); + PyObject *__pyx_v_rc; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + unsigned long __pyx_3; + PyObject *__pyx_4 = 0; + static char *__pyx_argnames[] = {"block","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_block); + Py_INCREF(__pyx_v_key); + __pyx_v_rc = Py_None; Py_INCREF(Py_None); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":29 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[0]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":29 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[1]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":30 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[0]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":30 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[1]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":30 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[2]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":30 */ + __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[3]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":31 */ + __pyx_1 = PyInt_FromLong(tea_encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; goto __pyx_L1;} + Py_DECREF(__pyx_v_rc); + __pyx_v_rc = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":32 */ + __pyx_2 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + __pyx_4 = PyList_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_4, 0, __pyx_2); + PyList_SET_ITEM(__pyx_4, 1, __pyx_1); + __pyx_2 = 0; + __pyx_1 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_4; + __pyx_4 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":33 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_4); + __Pyx_AddTraceback("_pyxtea._c_tea_encrypt"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_rc); + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_block); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + +static PyObject *__pyx_f_7_pyxtea__c_tea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_7_pyxtea__c_tea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_block = 0; + PyObject *__pyx_v_key = 0; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_v[2]); + unsigned long (__pyx_v_k[4]); + PyObject *__pyx_v_rc; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + unsigned long __pyx_3; + PyObject *__pyx_4 = 0; + static char *__pyx_argnames[] = {"block","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_block); + Py_INCREF(__pyx_v_key); + __pyx_v_rc = Py_None; Py_INCREF(Py_None); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":38 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[0]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":38 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[1]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":39 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[0]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":39 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[1]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":39 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[2]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":39 */ + __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[3]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":40 */ + __pyx_1 = PyInt_FromLong(tea_decipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; goto __pyx_L1;} + Py_DECREF(__pyx_v_rc); + __pyx_v_rc = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":41 */ + __pyx_2 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; goto __pyx_L1;} + __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; goto __pyx_L1;} + __pyx_4 = PyList_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_4, 0, __pyx_2); + PyList_SET_ITEM(__pyx_4, 1, __pyx_1); + __pyx_2 = 0; + __pyx_1 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_4; + __pyx_4 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":42 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_4); + __Pyx_AddTraceback("_pyxtea._c_tea_decrypt"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_rc); + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_block); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + +static PyObject *__pyx_f_7_pyxtea__c_xtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_7_pyxtea__c_xtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_block = 0; + PyObject *__pyx_v_key = 0; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_v[2]); + unsigned long (__pyx_v_k[4]); + PyObject *__pyx_v_rc; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + unsigned long __pyx_3; + PyObject *__pyx_4 = 0; + static char *__pyx_argnames[] = {"block","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_block); + Py_INCREF(__pyx_v_key); + __pyx_v_rc = Py_None; Py_INCREF(Py_None); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":49 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[0]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":49 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[1]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":50 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[0]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":50 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[1]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":50 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[2]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":50 */ + __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[3]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":51 */ + __pyx_1 = PyInt_FromLong(xtea_encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; goto __pyx_L1;} + Py_DECREF(__pyx_v_rc); + __pyx_v_rc = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":52 */ + __pyx_2 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} + __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} + __pyx_4 = PyList_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_4, 0, __pyx_2); + PyList_SET_ITEM(__pyx_4, 1, __pyx_1); + __pyx_2 = 0; + __pyx_1 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_4; + __pyx_4 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":53 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_4); + __Pyx_AddTraceback("_pyxtea._c_xtea_encrypt"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_rc); + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_block); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + +static PyObject *__pyx_f_7_pyxtea__c_xtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_7_pyxtea__c_xtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_block = 0; + PyObject *__pyx_v_key = 0; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_v[2]); + unsigned long (__pyx_v_k[4]); + PyObject *__pyx_v_rc; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + unsigned long __pyx_3; + PyObject *__pyx_4 = 0; + static char *__pyx_argnames[] = {"block","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_block); + Py_INCREF(__pyx_v_key); + __pyx_v_rc = Py_None; Py_INCREF(Py_None); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":58 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[0]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":58 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[1]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":59 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[0]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":59 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[1]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":59 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[2]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":59 */ + __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[3]) = __pyx_3; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":60 */ + __pyx_1 = PyInt_FromLong(xtea_decipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; goto __pyx_L1;} + Py_DECREF(__pyx_v_rc); + __pyx_v_rc = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":61 */ + __pyx_2 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; goto __pyx_L1;} + __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; goto __pyx_L1;} + __pyx_4 = PyList_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_4, 0, __pyx_2); + PyList_SET_ITEM(__pyx_4, 1, __pyx_1); + __pyx_2 = 0; + __pyx_1 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_4; + __pyx_4 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":62 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_4); + __Pyx_AddTraceback("_pyxtea._c_xtea_decrypt"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_rc); + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_block); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + +static PyObject *__pyx_n_len; +static PyObject *__pyx_n_ValueError; +static PyObject *__pyx_n_append; + +static PyObject *__pyx_k1p; + +static char (__pyx_k1[]) = "len(block) %i != rounds %i"; + +static PyObject *__pyx_f_7_pyxtea__c_xxtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_7_pyxtea__c_xxtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_block = 0; + PyObject *__pyx_v_key = 0; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_k[4]); + unsigned long (*__pyx_v_v); + int __pyx_v_rc; + int __pyx_v_size; + int __pyx_v_i; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + PyObject *__pyx_3 = 0; + int __pyx_4; + PyObject *__pyx_5 = 0; + unsigned long __pyx_6; + static char *__pyx_argnames[] = {"block","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_block); + Py_INCREF(__pyx_v_key); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":69 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;} + __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;} + Py_INCREF(__pyx_v_block); + PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_block); + __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_2); __pyx_2 = 0; + __pyx_4 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_v_size = __pyx_4; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":70 */ + __pyx_4 = (__pyx_v_size != __pyx_v_rounds); + if (__pyx_4) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":71 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; goto __pyx_L1;} + __pyx_2 = PyInt_FromLong(__pyx_v_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_rounds); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; goto __pyx_L1;} + __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_5, 0, __pyx_2); + PyTuple_SET_ITEM(__pyx_5, 1, __pyx_3); + __pyx_2 = 0; + __pyx_3 = 0; + __pyx_2 = PyNumber_Remainder(__pyx_k1p, __pyx_5); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + __Pyx_Raise(__pyx_1, __pyx_2, 0); + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_2); __pyx_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; goto __pyx_L1;} + goto __pyx_L2; + } + __pyx_L2:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":72 */ + __pyx_v_v = ((unsigned long (*))malloc(((sizeof(unsigned long )) * __pyx_v_size))); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":73 */ + for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":74 */ + __pyx_3 = PyInt_FromLong(__pyx_v_i); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_block, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_v[__pyx_v_i]) = __pyx_6; + } + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":75 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[0]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":75 */ + __pyx_3 = PyInt_FromLong(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[1]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":75 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[2]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":75 */ + __pyx_3 = PyInt_FromLong(3); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[3]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":76 */ + __pyx_v_rc = xxtea_encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":77 */ + __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; goto __pyx_L1;} + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":78 */ + for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":79 */ + __pyx_2 = PyObject_GetAttr(__pyx_v_result, __pyx_n_append); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong((__pyx_v_v[__pyx_v_i])); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; goto __pyx_L1;} + __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_5, 0, __pyx_3); + __pyx_3 = 0; + __pyx_1 = PyObject_CallObject(__pyx_2, __pyx_5); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + Py_DECREF(__pyx_5); __pyx_5 = 0; + Py_DECREF(__pyx_1); __pyx_1 = 0; + } + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":80 */ + free(__pyx_v_v); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":81 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_3); + Py_XDECREF(__pyx_5); + __Pyx_AddTraceback("_pyxtea._c_xxtea_encrypt"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_block); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + +static PyObject *__pyx_k2p; + +static char (__pyx_k2[]) = "len(block) %i != rounds %i"; + +static PyObject *__pyx_f_7_pyxtea__c_xxtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_7_pyxtea__c_xxtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_block = 0; + PyObject *__pyx_v_key = 0; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_k[4]); + unsigned long (*__pyx_v_v); + int __pyx_v_rc; + int __pyx_v_size; + int __pyx_v_i; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + PyObject *__pyx_3 = 0; + int __pyx_4; + PyObject *__pyx_5 = 0; + unsigned long __pyx_6; + static char *__pyx_argnames[] = {"block","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_block); + Py_INCREF(__pyx_v_key); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":86 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; goto __pyx_L1;} + __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; goto __pyx_L1;} + Py_INCREF(__pyx_v_block); + PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_block); + __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_2); __pyx_2 = 0; + __pyx_4 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_v_size = __pyx_4; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":87 */ + __pyx_4 = (__pyx_v_size != __pyx_v_rounds); + if (__pyx_4) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":88 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; goto __pyx_L1;} + __pyx_2 = PyInt_FromLong(__pyx_v_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_rounds); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; goto __pyx_L1;} + __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_5, 0, __pyx_2); + PyTuple_SET_ITEM(__pyx_5, 1, __pyx_3); + __pyx_2 = 0; + __pyx_3 = 0; + __pyx_2 = PyNumber_Remainder(__pyx_k2p, __pyx_5); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + __Pyx_Raise(__pyx_1, __pyx_2, 0); + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_2); __pyx_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; goto __pyx_L1;} + goto __pyx_L2; + } + __pyx_L2:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":89 */ + __pyx_v_v = ((unsigned long (*))malloc(((sizeof(unsigned long )) * __pyx_v_size))); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":90 */ + for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":91 */ + __pyx_3 = PyInt_FromLong(__pyx_v_i); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_block, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_v[__pyx_v_i]) = __pyx_6; + } + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":92 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[0]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":92 */ + __pyx_3 = PyInt_FromLong(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[1]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":92 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[2]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":92 */ + __pyx_3 = PyInt_FromLong(3); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[3]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":93 */ + __pyx_v_rc = xxtea_decipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":94 */ + __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; goto __pyx_L1;} + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":95 */ + for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":96 */ + __pyx_2 = PyObject_GetAttr(__pyx_v_result, __pyx_n_append); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong((__pyx_v_v[__pyx_v_i])); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; goto __pyx_L1;} + __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_5, 0, __pyx_3); + __pyx_3 = 0; + __pyx_1 = PyObject_CallObject(__pyx_2, __pyx_5); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + Py_DECREF(__pyx_5); __pyx_5 = 0; + Py_DECREF(__pyx_1); __pyx_1 = 0; + } + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":97 */ + free(__pyx_v_v); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_pyxtea.pyx":98 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_3); + Py_XDECREF(__pyx_5); + __Pyx_AddTraceback("_pyxtea._c_xxtea_decrypt"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_block); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + +static __Pyx_InternTabEntry __pyx_intern_tab[] = { + {&__pyx_n_ValueError, "ValueError"}, + {&__pyx_n__c_tea_decrypt, "_c_tea_decrypt"}, + {&__pyx_n__c_tea_encrypt, "_c_tea_encrypt"}, + {&__pyx_n__c_xtea_decrypt, "_c_xtea_decrypt"}, + {&__pyx_n__c_xtea_encrypt, "_c_xtea_encrypt"}, + {&__pyx_n__c_xxtea_decrypt, "_c_xxtea_decrypt"}, + {&__pyx_n__c_xxtea_encrypt, "_c_xxtea_encrypt"}, + {&__pyx_n_append, "append"}, + {&__pyx_n_len, "len"}, + {0, 0} +}; + +static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_k1p, __pyx_k1, sizeof(__pyx_k1)}, + {&__pyx_k2p, __pyx_k2, sizeof(__pyx_k2)}, + {0, 0, 0} +}; + +static struct PyMethodDef __pyx_methods[] = { + {"_c_tea_encrypt", (PyCFunction)__pyx_f_7_pyxtea__c_tea_encrypt, METH_VARARGS|METH_KEYWORDS, 0}, + {"_c_tea_decrypt", (PyCFunction)__pyx_f_7_pyxtea__c_tea_decrypt, METH_VARARGS|METH_KEYWORDS, 0}, + {"_c_xtea_encrypt", (PyCFunction)__pyx_f_7_pyxtea__c_xtea_encrypt, METH_VARARGS|METH_KEYWORDS, 0}, + {"_c_xtea_decrypt", (PyCFunctio... [truncated message content] |