summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwayne C. Litzenberger <dlitz@dlitz.net>2009-10-10 16:41:14 -0400
committerDwayne C. Litzenberger <dlitz@dlitz.net>2009-10-12 14:49:02 -0400
commit10b882261ae4022792c9f5e39d242d07ab769a5c (patch)
treed6301190c9dcaf093b43b38a5e8c170db36320b4
parent22fe3248e64938944d0a8e107552691dbf822d39 (diff)
downloadpycrypto-10b882261ae4022792c9f5e39d242d07ab769a5c.tar.gz
Counter: Add 'carry' attribute to counter objects
-rw-r--r--src/_counter.c13
-rw-r--r--src/_counter.h1
2 files changed, 12 insertions, 2 deletions
diff --git a/src/_counter.c b/src/_counter.c
index 7dc0f89..6964947 100644
--- a/src/_counter.c
+++ b/src/_counter.c
@@ -104,6 +104,9 @@ CounterObject_init(PCT_CounterObject *self, PyObject *args, PyObject *kwargs)
/* Set shortcut_disabled */
self->shortcut_disabled = disable_shortcut;
+ /* Clear the carry flag */
+ self->carry = 0;
+
return 0;
}
@@ -213,6 +216,7 @@ CounterLEObject_increment(PCT_CounterObject *self)
carry = tmp >> 8; /* This will only ever be 0 or 1 */
*p = tmp & 0xff;
}
+ self->carry = carry;
}
static void
@@ -230,6 +234,7 @@ CounterBEObject_increment(PCT_CounterObject *self)
carry = tmp >> 8; /* This will only ever be 0 or 1 */
*p = tmp & 0xff;
}
+ self->carry = carry;
}
static PyObject *
@@ -264,7 +269,9 @@ static PyObject *
CounterLEObject_getattr(PyObject *s, char *name)
{
PCT_CounterObject *self = (PCT_CounterObject *)s;
- if (!self->shortcut_disabled && strcmp(name, "__PCT_CTR_SHORTCUT__") == 0) {
+ if (strcmp(name, "carry") == 0) {
+ return PyInt_FromLong((long)self->carry);
+ } else if (!self->shortcut_disabled && strcmp(name, "__PCT_CTR_SHORTCUT__") == 0) {
/* Shortcut hack - See block_template.c */
Py_INCREF(Py_True);
return Py_True;
@@ -276,7 +283,9 @@ static PyObject *
CounterBEObject_getattr(PyObject *s, char *name)
{
PCT_CounterObject *self = (PCT_CounterObject *)s;
- if (!self->shortcut_disabled && strcmp(name, "__PCT_CTR_SHORTCUT__") == 0) {
+ if (strcmp(name, "carry") == 0) {
+ return PyInt_FromLong((long)self->carry);
+ } else if (!self->shortcut_disabled && strcmp(name, "__PCT_CTR_SHORTCUT__") == 0) {
/* Shortcut hack - See block_template.c */
Py_INCREF(Py_True);
return Py_True;
diff --git a/src/_counter.h b/src/_counter.h
index e7a5137..9735aab 100644
--- a/src/_counter.h
+++ b/src/_counter.h
@@ -37,6 +37,7 @@ typedef struct {
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 */
} PCT_CounterObject;
#endif /* PCT__COUNTER_H */