[Pymoul-svn] SF.net SVN: pymoul: [224] xtea/trunk/src/xtea
Status: Alpha
Brought to you by:
tiran
From: <ti...@us...> - 2007-03-02 16:28:17
|
Revision: 224 http://pymoul.svn.sourceforge.net/pymoul/?rev=224&view=rev Author: tiran Date: 2007-03-02 08:28:11 -0800 (Fri, 02 Mar 2007) Log Message: ----------- Redesign of the package. Moved common stuf to common Fixed broken naming in pyx code Modified Paths: -------------- xtea/trunk/src/xtea/__init__.py xtea/trunk/src/xtea/_xtea.c xtea/trunk/src/xtea/_xtea.pyx xtea/trunk/src/xtea/cxtea.c xtea/trunk/src/xtea/cxtea.h xtea/trunk/src/xtea/tests.py xtea/trunk/src/xtea/xtea.py Added Paths: ----------- xtea/trunk/src/xtea/_common.py Modified: xtea/trunk/src/xtea/__init__.py =================================================================== --- xtea/trunk/src/xtea/__init__.py 2007-03-02 14:54:09 UTC (rev 223) +++ xtea/trunk/src/xtea/__init__.py 2007-03-02 16:28:11 UTC (rev 224) @@ -1,7 +1,11 @@ # xtea package -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 +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 Added: xtea/trunk/src/xtea/_common.py =================================================================== --- xtea/trunk/src/xtea/_common.py (rev 0) +++ xtea/trunk/src/xtea/_common.py 2007-03-02 16:28:11 UTC (rev 224) @@ -0,0 +1,151 @@ +""" +""" +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 + +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) + + 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 + + def _ecb(self, block, func): + """Electronic Code Book encryption/decryption + + @type block: str + @param func: decrypt or encrypt function + @type func: callable + """ + raise NotImplementedError + + def _ofb(self, block): + """Output Feedback (OFB) encryption requires an IV + """ + raise NotImplementedError + Property changes on: xtea/trunk/src/xtea/_common.py ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Modified: xtea/trunk/src/xtea/_xtea.c =================================================================== --- xtea/trunk/src/xtea/_xtea.c 2007-03-02 14:54:09 UTC (rev 223) +++ xtea/trunk/src/xtea/_xtea.c 2007-03-02 16:28:11 UTC (rev 224) @@ -1,4 +1,4 @@ -/* Generated by Pyrex 0.9.4.1 on Fri Mar 2 15:53:19 2007 */ +/* Generated by Pyrex 0.9.5.1a on Fri Mar 2 17:24:15 2007 */ #include "Python.h" #include "structmember.h" @@ -17,26 +17,6 @@ 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; @@ -44,20 +24,32 @@ 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_xtea_encryptQuad; -static PyObject *__pyx_n__c_xxtea_decryptQuad; +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_n_XXX_c_xxtea_encrypt; +static PyObject *__pyx_n_XXX_c_xxtea_decrypt; -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; +static PyObject *__pyx_f_5_xtea__c_xtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5_xtea__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]); @@ -69,17 +61,28 @@ PyObject *__pyx_2 = 0; unsigned long __pyx_3; PyObject *__pyx_4 = 0; - 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; + 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":25 */ - (__pyx_v_v[0]) = __pyx_v_v0; + __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_block, __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_v[0]) = __pyx_3; /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":25 */ - (__pyx_v_v[1]) = __pyx_v_v1; + __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_block, __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_v[1]) = __pyx_3; /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":26 */ __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;} @@ -142,19 +145,19 @@ Py_XDECREF(__pyx_1); Py_XDECREF(__pyx_2); Py_XDECREF(__pyx_4); - __Pyx_AddTraceback("_xtea._c_xtea_encryptQuad"); + __Pyx_AddTraceback("_xtea._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_5_xtea__c_xxtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_f_5_xtea__c_xxtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - unsigned long __pyx_v_v0; - unsigned long __pyx_v_v1; +static PyObject *__pyx_f_5_xtea__c_xtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5_xtea__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]); @@ -166,17 +169,28 @@ PyObject *__pyx_2 = 0; unsigned long __pyx_3; PyObject *__pyx_4 = 0; - 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; + 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":34 */ - (__pyx_v_v[0]) = __pyx_v_v0; + __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_block, __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_v[0]) = __pyx_3; /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ - (__pyx_v_v[1]) = __pyx_v_v1; + __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_block, __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_v[1]) = __pyx_3; /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":35 */ __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;} @@ -211,7 +225,7 @@ (__pyx_v_k[3]) = __pyx_3; /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":36 */ - __pyx_1 = PyInt_FromLong(xxtea_decipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} + __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 = 36; goto __pyx_L1;} Py_DECREF(__pyx_v_rc); __pyx_v_rc = __pyx_1; __pyx_1 = 0; @@ -239,18 +253,24 @@ Py_XDECREF(__pyx_1); Py_XDECREF(__pyx_2); Py_XDECREF(__pyx_4); - __Pyx_AddTraceback("_xtea._c_xxtea_decryptQuad"); + __Pyx_AddTraceback("_xtea._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_5_xtea__c_xxtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_f_5_xtea__c_xxtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_block = 0; @@ -268,7 +288,8 @@ PyObject *__pyx_2 = 0; PyObject *__pyx_3 = 0; int __pyx_4; - unsigned long __pyx_5; + 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); @@ -288,87 +309,106 @@ __pyx_v_size = __pyx_4; /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":44 */ + __pyx_4 = (__pyx_v_size != __pyx_v_rounds); + if (__pyx_4) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":45 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; goto __pyx_L1;} + __pyx_2 = PyInt_FromLong(__pyx_v_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_rounds); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; goto __pyx_L1;} + __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; 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 = 45; 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 = 45; goto __pyx_L1;} + goto __pyx_L2; + } + __pyx_L2:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":46 */ __pyx_v_vsize = ((sizeof(unsigned long )) * __pyx_v_size); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":45 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":47 */ __pyx_v_v = ((unsigned long (*))malloc(__pyx_v_vsize)); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":46 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":48 */ for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":47 */ - __pyx_1 = PyInt_FromLong(__pyx_v_i); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - (__pyx_v_v[__pyx_v_i]) = __pyx_5; - __pyx_L2:; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":49 */ + __pyx_3 = PyInt_FromLong(__pyx_v_i); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_block, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; 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 = 49; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_v[__pyx_v_i]) = __pyx_6; } - __pyx_L3:; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":48 */ - __pyx_3 = PyInt_FromLong(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} - __pyx_1 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} - Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_1); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.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_v_k[0]) = __pyx_5; + __pyx_6 = 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_6; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":48 */ - __pyx_2 = PyInt_FromLong(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} - __pyx_3 = PyObject_GetItem(__pyx_v_key, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":50 */ + __pyx_3 = PyInt_FromLong(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} Py_DECREF(__pyx_3); __pyx_3 = 0; - (__pyx_v_k[1]) = __pyx_5; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[1]) = __pyx_6; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":48 */ - __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.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_5 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + __pyx_6 = 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_5; + (__pyx_v_k[2]) = __pyx_6; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":48 */ - __pyx_3 = PyInt_FromLong(3); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} - __pyx_1 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":50 */ + __pyx_3 = PyInt_FromLong(3); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_1); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - (__pyx_v_k[3]) = __pyx_5; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[3]) = __pyx_6; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":49 */ - __pyx_v_rc = xtea_encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":51 */ + __pyx_v_rc = xxtea_encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":50 */ - __pyx_2 = PyList_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":52 */ + __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} Py_DECREF(__pyx_v_result); - __pyx_v_result = __pyx_2; - __pyx_2 = 0; + __pyx_v_result = __pyx_1; + __pyx_1 = 0; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":51 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":53 */ for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":52 */ - __pyx_3 = PyObject_GetAttr(__pyx_v_result, __pyx_n_append); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} - __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[__pyx_v_i])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} - __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} - PyTuple_SET_ITEM(__pyx_2, 0, __pyx_1); - __pyx_1 = 0; - __pyx_1 = PyObject_CallObject(__pyx_3, __pyx_2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} - Py_DECREF(__pyx_3); __pyx_3 = 0; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":54 */ + __pyx_2 = PyObject_GetAttr(__pyx_v_result, __pyx_n_append); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong((__pyx_v_v[__pyx_v_i])); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;} + __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; 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 = 54; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; + Py_DECREF(__pyx_5); __pyx_5 = 0; Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_L4:; } - __pyx_L5:; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":53 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":55 */ free(__pyx_v_v); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":54 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":56 */ Py_INCREF(__pyx_v_result); __pyx_r = __pyx_v_result; goto __pyx_L0; @@ -379,6 +419,7 @@ Py_XDECREF(__pyx_1); Py_XDECREF(__pyx_2); Py_XDECREF(__pyx_3); + Py_XDECREF(__pyx_5); __Pyx_AddTraceback("_xtea._c_xxtea_encrypt"); __pyx_r = 0; __pyx_L0:; @@ -388,6 +429,10 @@ return __pyx_r; } +static PyObject *__pyx_k2p; + +static char (__pyx_k2[]) = "len(block) %i != rounds %i"; + static PyObject *__pyx_f_5_xtea__c_xxtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_f_5_xtea__c_xxtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_block = 0; @@ -405,107 +450,127 @@ PyObject *__pyx_2 = 0; PyObject *__pyx_3 = 0; int __pyx_4; - unsigned long __pyx_5; + 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/_xtea.pyx":59 */ - __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} - __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":61 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; goto __pyx_L1;} + __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; 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 = 59; goto __pyx_L1;} + __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; 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 = 59; goto __pyx_L1;} + __pyx_4 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; goto __pyx_L1;} Py_DECREF(__pyx_3); __pyx_3 = 0; __pyx_v_size = __pyx_4; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":60 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":62 */ + __pyx_4 = (__pyx_v_size != __pyx_v_rounds); + if (__pyx_4) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":63 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} + __pyx_2 = PyInt_FromLong(__pyx_v_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_rounds); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} + __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; 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 = 63; 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 = 63; goto __pyx_L1;} + goto __pyx_L2; + } + __pyx_L2:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":64 */ __pyx_v_vsize = ((sizeof(unsigned long )) * __pyx_v_size); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":61 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":65 */ __pyx_v_v = ((unsigned long (*))malloc(__pyx_v_vsize)); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":62 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":66 */ for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":63 */ - __pyx_1 = PyInt_FromLong(__pyx_v_i); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - (__pyx_v_v[__pyx_v_i]) = __pyx_5; - __pyx_L2:; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":67 */ + __pyx_3 = PyInt_FromLong(__pyx_v_i); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_block, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; 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 = 67; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_v[__pyx_v_i]) = __pyx_6; } - __pyx_L3:; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":64 */ - __pyx_3 = PyInt_FromLong(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} - __pyx_1 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} - Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_1); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":68 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; - (__pyx_v_k[0]) = __pyx_5; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[0]) = __pyx_6; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":64 */ - __pyx_2 = PyInt_FromLong(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} - __pyx_3 = PyObject_GetItem(__pyx_v_key, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":68 */ + __pyx_3 = PyInt_FromLong(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} Py_DECREF(__pyx_3); __pyx_3 = 0; - (__pyx_v_k[1]) = __pyx_5; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[1]) = __pyx_6; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":64 */ - __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":68 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; - (__pyx_v_k[2]) = __pyx_5; + (__pyx_v_k[2]) = __pyx_6; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":64 */ - __pyx_3 = PyInt_FromLong(3); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} - __pyx_1 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":68 */ + __pyx_3 = PyInt_FromLong(3); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_1); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - (__pyx_v_k[3]) = __pyx_5; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[3]) = __pyx_6; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":65 */ - __pyx_v_rc = xtea_encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":69 */ + __pyx_v_rc = xxtea_decipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":66 */ - __pyx_2 = PyList_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":70 */ + __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; goto __pyx_L1;} Py_DECREF(__pyx_v_result); - __pyx_v_result = __pyx_2; - __pyx_2 = 0; + __pyx_v_result = __pyx_1; + __pyx_1 = 0; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":67 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":71 */ for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":68 */ - __pyx_3 = PyObject_GetAttr(__pyx_v_result, __pyx_n_append); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} - __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[__pyx_v_i])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} - __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} - PyTuple_SET_ITEM(__pyx_2, 0, __pyx_1); - __pyx_1 = 0; - __pyx_1 = PyObject_CallObject(__pyx_3, __pyx_2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} - Py_DECREF(__pyx_3); __pyx_3 = 0; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":72 */ + __pyx_2 = PyObject_GetAttr(__pyx_v_result, __pyx_n_append); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong((__pyx_v_v[__pyx_v_i])); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; goto __pyx_L1;} + __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; 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 = 72; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; + Py_DECREF(__pyx_5); __pyx_5 = 0; Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_L4:; } - __pyx_L5:; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":69 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":73 */ free(__pyx_v_v); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":70 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":74 */ Py_INCREF(__pyx_v_result); __pyx_r = __pyx_v_result; goto __pyx_L0; @@ -516,6 +581,7 @@ Py_XDECREF(__pyx_1); Py_XDECREF(__pyx_2); Py_XDECREF(__pyx_3); + Py_XDECREF(__pyx_5); __Pyx_AddTraceback("_xtea._c_xxtea_decrypt"); __pyx_r = 0; __pyx_L0:; @@ -525,21 +591,326 @@ return __pyx_r; } +static PyObject *__pyx_k3p; + +static char (__pyx_k3[]) = "len(block) %i != rounds %i"; + +static PyObject *__pyx_f_5_xtea_XXX_c_xxtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5_xtea_XXX_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[2]); + int __pyx_v_rc; + int __pyx_v_size; + 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/_xtea.pyx":79 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; goto __pyx_L1;} + __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; 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 = 79; 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 = 79; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_v_size = __pyx_4; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":80 */ + __pyx_4 = (__pyx_v_size != __pyx_v_rounds); + if (__pyx_4) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":81 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; goto __pyx_L1;} + __pyx_2 = PyInt_FromLong(__pyx_v_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_rounds); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; goto __pyx_L1;} + __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; 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_k3p, __pyx_5); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; 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 = 81; goto __pyx_L1;} + goto __pyx_L2; + } + __pyx_L2:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":82 */ + __pyx_3 = PyInt_FromLong(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_block, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; 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 = 82; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_v[0]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":82 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; 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 = 82; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[1]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":83 */ + __pyx_3 = PyInt_FromLong(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; 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 = 83; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[0]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":83 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; 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 = 83; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[1]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":83 */ + __pyx_3 = PyInt_FromLong(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; 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 = 83; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[2]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":83 */ + __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; 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 = 83; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[3]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":84 */ + __pyx_v_rc = xxtea_encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":85 */ + __pyx_3 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; goto __pyx_L1;} + __pyx_5 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; goto __pyx_L1;} + __pyx_1 = PyList_New(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_1, 0, __pyx_3); + PyList_SET_ITEM(__pyx_1, 1, __pyx_5); + __pyx_3 = 0; + __pyx_5 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":86 */ + 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("_xtea.XXX_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_k4p; + +static char (__pyx_k4[]) = "len(block) %i != rounds %i"; + +static PyObject *__pyx_f_5_xtea_XXX_c_xxtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5_xtea_XXX_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[2]); + int __pyx_v_rc; + int __pyx_v_size; + 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/_xtea.pyx":91 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; goto __pyx_L1;} + __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; 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 = 91; 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 = 91; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_v_size = __pyx_4; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":92 */ + __pyx_4 = (__pyx_v_size != __pyx_v_rounds); + if (__pyx_4) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":93 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; goto __pyx_L1;} + __pyx_2 = PyInt_FromLong(__pyx_v_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_rounds); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; goto __pyx_L1;} + __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; 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_k4p, __pyx_5); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; 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 = 93; goto __pyx_L1;} + goto __pyx_L2; + } + __pyx_L2:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":94 */ + __pyx_3 = PyInt_FromLong(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_block, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; 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 = 94; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_v[0]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":94 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; 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 = 94; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[1]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":95 */ + __pyx_3 = PyInt_FromLong(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; 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 = 95; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[0]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":95 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; 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 = 95; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[1]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":95 */ + __pyx_3 = PyInt_FromLong(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; 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 = 95; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[2]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":95 */ + __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; 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 = 95; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[3]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":96 */ + __pyx_v_rc = xxtea_decipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":97 */ + __pyx_3 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; goto __pyx_L1;} + __pyx_5 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; goto __pyx_L1;} + __pyx_1 = PyList_New(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_1, 0, __pyx_3); + PyList_SET_ITEM(__pyx_1, 1, __pyx_5); + __pyx_3 = 0; + __pyx_5 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.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("_xtea.XXX_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__c_xtea_encryptQuad, "_c_xtea_encryptQuad"}, + {&__pyx_n_ValueError, "ValueError"}, + {&__pyx_n_XXX_c_xxtea_decrypt, "XXX_c_xxtea_decrypt"}, + {&__pyx_n_XXX_c_xxtea_encrypt, "XXX_c_xxtea_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_decryptQuad, "_c_xxtea_decryptQuad"}, {&__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)}, + {&__pyx_k3p, __pyx_k3, sizeof(__pyx_k3)}, + {&__pyx_k4p, __pyx_k4, sizeof(__pyx_k4)}, + {0, 0, 0} +}; + static struct PyMethodDef __pyx_methods[] = { - {"_c_xtea_encryptQuad", (PyCFunction)__pyx_f_5_xtea__c_xtea_encryptQuad, METH_VARARGS|METH_KEYWORDS, 0}, - {"_c_xxtea_decryptQuad", (PyCFunction)__pyx_f_5_xtea__c_xxtea_decryptQuad, METH_VARARGS|METH_KEYWORDS, 0}, + {"_c_xtea_encrypt", (PyCFunction)__pyx_f_5_xtea__c_xtea_encrypt, METH_VARARGS|METH_KEYWORDS, 0}, + {"_c_xtea_decrypt", (PyCFunction)__pyx_f_5_xtea__c_xtea_decrypt, METH_VARARGS|METH_KEYWORDS, 0}, {"_c_xxtea_encrypt", (PyCFunction)__pyx_f_5_xtea__c_xxtea_encrypt, METH_VARARGS|METH_KEYWORDS, 0}, {"_c_xxtea_decrypt", (PyCFunction)__pyx_f_5_xtea__c_xxtea_decrypt, METH_VARARGS|METH_KEYWORDS, 0}, + {"XXX_c_xxtea_encrypt", (PyCFunction)__pyx_f_5_xtea_XXX_c_xxtea_encrypt, METH_VARARGS|METH_KEYWORDS, 0}, + {"XXX_c_xxtea_decrypt", (PyCFunction)__pyx_f_5_xtea_XXX_c_xxtea_decrypt, METH_VARARGS|METH_KEYWORDS, 0}, {0, 0, 0, 0} }; @@ -554,8 +925,9 @@ 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/_xtea.pyx":56 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":88 */ return; __pyx_L1:; __Pyx_AddTraceback("_xtea"); @@ -579,6 +951,64 @@ 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); @@ -589,6 +1019,16 @@ 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" Modified: xtea/trunk/src/xtea/_xtea.pyx =================================================================== --- xtea/trunk/src/xtea/_xtea.pyx 2007-03-02 14:54:09 UTC (rev 223) +++ xtea/trunk/src/xtea/_xtea.pyx 2007-03-02 16:28:11 UTC (rev 224) @@ -19,21 +19,21 @@ int xxtea_decipher(ULong *v, ULong *k, UInt n) int xxtea_encipher(ULong *v, ULong *k, UInt n) -def _c_xtea_encryptQuad(ULong v0, ULong v1, object key, UInt rounds): +def _c_xtea_encrypt(object block, object key, UInt rounds): cdef ULong v[2] cdef ULong k[4] - v[0] = v0; v[1] = v1 + 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_xxtea_decryptQuad(ULong v0, ULong v1, object key, UInt rounds): +def _c_xtea_decrypt(object block, object key, UInt rounds): cdef ULong v[2] cdef ULong k[4] - v[0] = v0; v[1] = v1 + 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 = xxtea_decipher(v, k, rounds) + rc = xtea_decipher(v, k, rounds) result = [v[0], v[1]] return result @@ -41,12 +41,14 @@ cdef ULong k[4], *v cdef int rc, size, vsize, i size = len(block) + if size != rounds: + raise ValueError, "len(block) %i != rounds %i" % (size, rounds) vsize = sizeof(ULong) * size v = <ULong *>malloc(vsize) 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 = xtea_encipher(v, k, rounds) + rc = xxtea_encipher(v, k, rounds) result = [] for i from 0 <= i < size: result.append(v[i]) @@ -57,14 +59,40 @@ cdef ULong k[4], *v cdef int rc, size, vsize, i size = len(block) + if size != rounds: + raise ValueError, "len(block) %i != rounds %i" % (size, rounds) vsize = sizeof(U... [truncated message content] |