summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDwayne Litzenberger <dlitz@dlitz.net>2013-07-14 10:55:06 -0700
committerDwayne Litzenberger <dlitz@dlitz.net>2013-07-14 18:32:04 -0700
commitb6ad2b47d9b7f3799c29097b4324dff2540fe77d (patch)
treeadd26f4b539dadecb45f21e265f04c827db195db /src
parent0ee73a1b571f540cfca8d656853f2bc3df2e3767 (diff)
downloadpycrypto-b6ad2b47d9b7f3799c29097b4324dff2540fe77d.tar.gz
Counter: Deprecate disable_shortcut; Remove __PCT_CTR_SHORTCUT__ entirely
The `disable_shortcut` option served as a workaround in case `__PCT_CTR_SHORTCUT__` leaked through a wrapper object, but I don't think anyone actually used it, and it was a bad idea to expose it as part of the public API. Now that we do strong type checking inside block_template.c, there shoujld be no need to ever use this option. It's now a no-op, retained for backward compatibility only. It will be removed in some future version of PyCrypto.
Diffstat (limited to 'src')
-rw-r--r--src/_counter.c24
-rw-r--r--src/_counter.h1
-rw-r--r--src/block_template.c1
3 files changed, 4 insertions, 22 deletions
diff --git a/src/_counter.c b/src/_counter.c
index c1f1e5f..729fc9e 100644
--- a/src/_counter.c
+++ b/src/_counter.c
@@ -42,11 +42,10 @@ CounterObject_init(PCT_CounterObject *self, PyObject *args, PyObject *kwargs)
PyStringObject *prefix=NULL, *suffix=NULL, *initval=NULL;
#endif
int allow_wraparound = 0;
- int disable_shortcut = 0;
Py_ssize_t size;
- static char *kwlist[] = {"prefix", "suffix", "initval", "allow_wraparound", "disable_shortcut", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "SSS|ii", kwlist, &prefix, &suffix, &initval, &allow_wraparound, &disable_shortcut))
+ static char *kwlist[] = {"prefix", "suffix", "initval", "allow_wraparound", NULL};
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "SSS|i", kwlist, &prefix, &suffix, &initval, &allow_wraparound))
return -1;
/* Check string size and set nbytes */
@@ -115,8 +114,7 @@ CounterObject_init(PCT_CounterObject *self, PyObject *args, PyObject *kwargs)
memcpy(self->p, PyBytes_AS_STRING(initval), self->nbytes);
memcpy(self->p + self->nbytes, PyBytes_AS_STRING(suffix), PyBytes_GET_SIZE(suffix));
- /* Set shortcut_disabled and allow_wraparound */
- self->shortcut_disabled = disable_shortcut;
+ /* Set allow_wraparound */
self->allow_wraparound = allow_wraparound;
/* Clear the carry flag */
@@ -322,14 +320,6 @@ CounterLEObject_getattr(PyObject *s, char *name)
if (strcmp(name, "carry") == 0) {
#endif
return PyLong_FromLong((long)self->carry);
-#ifdef IS_PY3K
- } else if (!self->shortcut_disabled && PyUnicode_CompareWithASCIIString(attr, "__PCT_CTR_SHORTCUT__") == 0) {
-#else
- } else if (!self->shortcut_disabled && strcmp(name, "__PCT_CTR_SHORTCUT__") == 0) {
-#endif
- /* Shortcut hack - See block_template.c */
- Py_INCREF(Py_True);
- return Py_True;
}
#ifdef IS_PY3K
generic:
@@ -356,14 +346,6 @@ CounterBEObject_getattr(PyObject *s, char *name)
if (strcmp(name, "carry") == 0) {
#endif
return PyLong_FromLong((long)self->carry);
-#ifdef IS_PY3K
- } else if (!self->shortcut_disabled && PyUnicode_CompareWithASCIIString(attr, "__PCT_CTR_SHORTCUT__") == 0) {
-#else
- } else if (!self->shortcut_disabled && strcmp(name, "__PCT_CTR_SHORTCUT__") == 0) {
-#endif
- /* Shortcut hack - See block_template.c */
- Py_INCREF(Py_True);
- return Py_True;
}
#ifdef IS_PY3K
generic:
diff --git a/src/_counter.h b/src/_counter.h
index 32c320b..e08757a 100644
--- a/src/_counter.h
+++ b/src/_counter.h
@@ -35,7 +35,6 @@ typedef struct {
uint8_t *p; /* Pointer to the part of the buffer that we're allowed to update */
uint16_t nbytes; /* The number of bytes that from .p that are part of the counter */
void (*inc_func)(void *); /* Pointer to the counter increment function */
- int shortcut_disabled; /* This gets set to a non-zero value when the shortcut mechanism is disabled */
int carry; /* This gets set by Counter*Object_increment when the counter wraps around */
int allow_wraparound; /* When this is false, we raise OverflowError on next_value() or __call__() when the counter wraps around */
} PCT_CounterObject;
diff --git a/src/block_template.c b/src/block_template.c
index 3e19eca..c655509 100644
--- a/src/block_template.c
+++ b/src/block_template.c
@@ -801,6 +801,7 @@ _MODULE_NAME (void)
PyModule_AddIntConstant(m, "block_size", BLOCK_SIZE);
PyModule_AddIntConstant(m, "key_size", KEY_SIZE);
+ /* Import CounterBE and CounterLE from the _counter module */
Py_CLEAR(_counter_module);
_counter_module = PyImport_ImportModule("Crypto.Util._counter");
if (_counter_module) {