You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
python-crypto/python-crypto-2.6.1-python3...

164 lines
4.3 KiB

--- src/block_template.c
+++ src/block_template.c
@@ -33,6 +33,7 @@
#include <string.h>
#endif
+#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycrypto_compat.h"
#include "modsupport.h"
@@ -123,7 +124,8 @@ ALGnew(PyObject *self, PyObject *args, P
{
unsigned char *key, *IV;
ALGobject * new=NULL;
- int keylen, IVlen=0, mode=MODE_ECB, segment_size=0;
+ Py_ssize_t keylen, IVlen=0;
+ int mode=MODE_ECB, segment_size=0;
PyObject *counter = NULL;
int counter_shortcut = 0;
#ifdef PCT_ARC2_MODULE
@@ -161,7 +163,7 @@ ALGnew(PyObject *self, PyObject *args, P
{
PyErr_Format(PyExc_ValueError,
"Key must be %i bytes long, not %i",
- KEY_SIZE, keylen);
+ KEY_SIZE, (int)keylen);
return NULL;
}
if (KEY_SIZE==0 && keylen==0)
@@ -242,7 +244,7 @@ ALGnew(PyObject *self, PyObject *args, P
new->st.effective_keylen = effective_keylen;
#endif
- block_init(&(new->st), key, keylen);
+ block_init(&(new->st), key, (int)keylen);
if (PyErr_Occurred())
{
Py_DECREF(new);
@@ -250,7 +252,7 @@ ALGnew(PyObject *self, PyObject *args, P
}
memset(new->IV, 0, BLOCK_SIZE);
memset(new->oldCipher, 0, BLOCK_SIZE);
- memcpy(new->IV, IV, IVlen);
+ memcpy(new->IV, IV, (size_t)IVlen);
new->mode = mode;
new->count=BLOCK_SIZE; /* stores how many bytes in new->oldCipher have been used */
return new;
@@ -265,10 +267,12 @@ ALG_Encrypt(ALGobject *self, PyObject *a
unsigned char *buffer, *str;
unsigned char temp[BLOCK_SIZE];
int i, j, len;
+ Py_ssize_t param_len;
PyObject *result;
- if (!PyArg_Parse(args, "s#", &str, &len))
+ if (!PyArg_Parse(args, "s#", &str, &param_len))
return NULL;
+ len = (int)param_len;
if (len==0) /* Handle empty string */
{
return PyBytes_FromStringAndSize(NULL, 0);
@@ -497,14 +501,16 @@ ALG_Decrypt(ALGobject *self, PyObject *a
unsigned char *buffer, *str;
unsigned char temp[BLOCK_SIZE];
int i, j, len;
+ Py_ssize_t param_len;
PyObject *result;
/* CTR mode decryption is identical to encryption */
if (self->mode == MODE_CTR)
return ALG_Encrypt(self, args);
- if (!PyArg_Parse(args, "s#", &str, &len))
+ if (!PyArg_Parse(args, "s#", &str, &param_len))
return NULL;
+ len = (int)param_len;
if (len==0) /* Handle empty string */
{
return PyBytes_FromStringAndSize(NULL, 0);
--- src/hash_template.c
+++ src/hash_template.c
@@ -30,6 +30,7 @@
#ifdef _HAVE_STDC_HEADERS
#include <string.h>
#endif
+#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycrypto_compat.h"
@@ -163,7 +164,7 @@ static PyObject *
ALG_update(ALGobject *self, PyObject *args)
{
unsigned char *cp;
- int len;
+ Py_ssize_t len;
if (!PyArg_ParseTuple(args, "s#", &cp, &len))
return NULL;
@@ -273,7 +274,7 @@ ALG_new(PyObject *self, PyObject *args)
{
ALGobject *new;
unsigned char *cp = NULL;
- int len;
+ Py_ssize_t len;
if ((new = newALGobject()) == NULL)
return NULL;
--- src/stream_template.c
+++ src/stream_template.c
@@ -33,6 +33,7 @@
#include <string.h>
#endif
+#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycrypto_compat.h"
#include "modsupport.h"
@@ -100,7 +101,7 @@ ALGnew(PyObject *self, PyObject *args, P
{
unsigned char *key;
ALGobject * new;
- int keylen;
+ Py_ssize_t keylen;
new = newALGobject();
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "s#", kwlist,
@@ -124,7 +125,7 @@ ALGnew(PyObject *self, PyObject *args, P
"the null string (0 bytes long)");
return NULL;
}
- stream_init(&(new->st), key, keylen);
+ stream_init(&(new->st), key, (int)keylen);
if (PyErr_Occurred())
{
Py_DECREF(new);
@@ -141,10 +142,12 @@ ALG_Encrypt(ALGobject *self, PyObject *a
{
unsigned char *buffer, *str;
int len;
+ Py_ssize_t param_len;
PyObject *result;
- if (!PyArg_Parse(args, "s#", &str, &len))
+ if (!PyArg_Parse(args, "s#", &str, &param_len))
return NULL;
+ len = (int)param_len;
if (len == 0) /* Handle empty string */
{
return PyBytes_FromStringAndSize(NULL, 0);
@@ -173,10 +176,12 @@ ALG_Decrypt(ALGobject *self, PyObject *a
{
unsigned char *buffer, *str;
int len;
+ Py_ssize_t param_len;
PyObject *result;
- if (!PyArg_Parse(args, "s#", &str, &len))
+ if (!PyArg_Parse(args, "s#", &str, &param_len))
return NULL;
+ len = (int)param_len;
if (len == 0) /* Handle empty string */
{
return PyBytes_FromStringAndSize(NULL, 0);