#include <longintrepr.h>
#include <structmember.h>
-#include <mLib/darray.h>
#include <mLib/dstr.h>
#include <mLib/macros.h>
#include <mLib/quis.h>
#include <catacomb/blkc.h>
#include <catacomb/gcipher.h>
+#include <catacomb/gaead.h>
#include <catacomb/ghash.h>
#include <catacomb/gmac.h>
#include <catacomb/md5.h>
#include <catacomb/share.h>
#include <catacomb/gfshare.h>
+/*----- Other preliminaries -----------------------------------------------*/
+
+#define GOBBLE_SEMI extern int notexist
+#if defined(__GNUC__) && defined(__ELF__)
+# define PRIVATE_SYMBOLS _Pragma("GCC visibility push(hidden)") GOBBLE_SEMI
+# define PUBLIC_SYMBOLS _Pragma("GCC visibility pop") GOBBLE_SEMI
+# define EXPORT __attribute__((__visibility__("default")))
+#else
+# define PRIVATE_SYMBOLS GOBBLE_SEMI
+# define PUBLIC_SYMBOLS GOBBLE_SEMI
+# define EXPORT
+#endif
+
+PRIVATE_SYMBOLS;
+
/*----- Utility macros ----------------------------------------------------*/
#define RETURN_OBJ(obj) do { Py_INCREF(obj); return (obj); } while (0)
goto end; \
} while (0)
#define VALERR(str) EXCERR(PyExc_ValueError, str)
+#define OVFERR(str) EXCERR(PyExc_OverflowError, str)
#define TYERR(str) EXCERR(PyExc_TypeError, str)
+#define IXERR(str) EXCERR(PyExc_IndexError, str)
#define ZDIVERR(str) EXCERR(PyExc_ZeroDivisionError, str)
#define SYSERR(str) EXCERR(PyExc_SystemError, str)
#define NIERR(str) EXCERR(PyExc_NotImplementedError, str)
return (0); \
}
-#if PY_VERSION_HEX < 0x02050000 /* Compatibility hack */
-# define ht_name name
-# define ht_type type
-#endif
-
#define root_pytype 0
#define type_pytype &PyType_Type
#define INITTYPE_META(ty, base, meta) do { \
#define INITTYPE(ty, base) INITTYPE_META(ty, base, type)
extern PyObject *home_module;
+extern PyObject *modname;
#define INSERT(name, ob) do { \
PyObject *_o = (PyObject *)(ob); \
return (d); \
}
+#define KWLIST (/*unconst*/ char **)kwlist
+
struct nameval { const char *name; unsigned f; unsigned long value; };
#define CF_SIGNED 1u
extern void setconstants(PyObject *, const struct nameval *);
/*----- Bytestrings -------------------------------------------------------*/
-PyTypeObject *bytestring_pyobj;
PyObject *bytestring_pywrap(const void *, size_t);
PyObject *bytestring_pywrapbuf(buf *);
field *f;
} field_pyobj;
-extern PyTypeObject *fe_pytype;
-#define FE_PYCHECK(o) PyObject_TypeCheck((o), fe_pytype)
-#define FE_F(o) (((fe_pyobj *)(o))->f)
-#define FE_FOBJ(o) ((PyObject *)(o)->ob_type)
-#define FE_X(o) (((fe_pyobj *)(o))->x)
-extern PyObject *fe_pywrap(PyObject *, mp *);
-
-typedef struct fe_pyobj {
- PyObject_HEAD
- field *f;
- mp *x;
-} fe_pyobj;
-
extern PyTypeObject *field_pytype;
extern PyTypeObject *primefield_pytype;
extern PyTypeObject *niceprimefield_pytype;
extern PyObject *field_pywrap(field *);
extern field *field_copy(field *);
+typedef struct fe_pyobj {
+ PyObject_HEAD
+ field *f;
+ mp *x;
+} fe_pyobj;
+
+extern PyTypeObject *fe_pytype;
+#define FE_PYCHECK(o) PyObject_TypeCheck((o), fe_pytype)
+#define FE_F(o) (((fe_pyobj *)(o))->f)
+#define FE_FOBJ(o) ((PyObject *)(o)->ob_type)
+#define FE_X(o) (((fe_pyobj *)(o))->x)
+extern PyObject *fe_pywrap(PyObject *, mp *);
+
/*----- Elliptic curves ---------------------------------------------------*/
+typedef struct eccurve_pyobj {
+ PyHeapTypeObject ty;
+ ec_curve *c;
+ PyObject *fobj;
+} eccurve_pyobj;
+
+extern PyTypeObject *eccurve_pytype;
+extern PyTypeObject *ecprimecurve_pytype;
+extern PyTypeObject *ecprimeprojcurve_pytype;
+extern PyTypeObject *ecbincurve_pytype;
+extern PyTypeObject *ecbinprojcurve_pytype;
+#define ECCURVE_PYCHECK(o) PyObject_TypeCheck((o), eccurve_pytype)
+#define ECCURVE_C(o) (((eccurve_pyobj *)(o))->c)
+#define ECCURVE_FOBJ(o) (((eccurve_pyobj *)(o))->fobj)
+extern PyObject *eccurve_pywrap(PyObject *, ec_curve *);
+extern ec_curve *eccurve_copy(ec_curve *);
+
typedef struct ecpt_pyobj {
PyObject_HEAD
ec_curve *c;
extern void getecptout(ec *, PyObject *);
extern int convecpt(PyObject *, void *);
-typedef struct eccurve_pyobj {
- PyHeapTypeObject ty;
- ec_curve *c;
- PyObject *fobj;
-} eccurve_pyobj;
-
-extern PyTypeObject *eccurve_pytype;
-extern PyTypeObject *ecprimecurve_pytype;
-extern PyTypeObject *ecprimeprojcurve_pytype;
-extern PyTypeObject *ecbincurve_pytype;
-extern PyTypeObject *ecbinprojcurve_pytype;
-#define ECCURVE_PYCHECK(o) PyObject_TypeCheck((o), eccurve_pytype)
-#define ECCURVE_C(o) (((eccurve_pyobj *)(o))->c)
-#define ECCURVE_FOBJ(o) (((eccurve_pyobj *)(o))->fobj)
-extern PyObject *eccurve_pywrap(PyObject *, ec_curve *);
-extern ec_curve *eccurve_copy(ec_curve *);
-
typedef struct ecinfo_pyobj {
PyObject_HEAD
ec_info ei;
/*----- Cyclic groups -----------------------------------------------------*/
-typedef struct fginfo_pyobj {
- PyObject_HEAD
- gprime_param dp;
-} fginfo_pyobj;
-
-PyTypeObject *fginfo_pytype, *dhinfo_pytype, *bindhinfo_pytype;
-#define FGINFO_DP(fg) (&((fginfo_pyobj *)(fg))->dp)
-PyObject *fginfo_pywrap(gprime_param *, PyTypeObject *);
-
typedef struct ge_pyobj {
PyObject_HEAD
ge *x;
} group_pyobj;
extern PyTypeObject *group_pytype;
-extern PyTypeObject *primegroup_pytype, *bingroup_pytype, *ecgroup_pytype;
#define GROUP_G(o) (((group_pyobj *)(o))->g)
extern PyObject *group_pywrap(group *);
extern group *group_copy(group *);
grand *r;
} grand_pyobj;
-extern PyTypeObject *grand_pytype, *truerand_pytype;
-extern PyTypeObject *lcrand_pytype,* fibrand_pytype;
-extern PyTypeObject *dsarand_pytype, *bbs_pytype;
+extern PyTypeObject *grand_pytype;
extern PyObject *rand_pyobj;
#define GRAND_PYCHECK(o) PyObject_TypeCheck((o), grand_pytype)
#define GRAND_F(o) (((grand_pyobj *)(o))->f)
extern PyObject *grand_pywrap(grand *, unsigned);
extern int convgrand(PyObject *, void *);
-/*----- Key sizes ---------------------------------------------------------*/
-
-typedef struct keysz_pyobj {
- PyObject_HEAD
- int dfl;
-} keysz_pyobj;
-
-typedef struct keyszrange_pyobj {
- PyObject_HEAD
- int dfl;
- int min, max, mod;
-} keyszrange_pyobj;
-
-typedef struct keyszset_pyobj {
- PyObject_HEAD
- int dfl;
- PyObject *set;
-} keyszset_pyobj;
-
-#define KEYSZ_PYCHECK(o) PyObject_TypeCheck((o), keysz_pytype)
-extern PyObject *keysz_pywrap(const octet *);
-
/*----- Symmetric cryptography --------------------------------------------*/
-typedef struct gccipher_pyobj {
- PyHeapTypeObject ty;
- gccipher *cc;
-} gccipher_pyobj;
+extern PyObject *keysz_pywrap(const octet *);
-extern PyTypeObject *gccipher_pytype;
-#define GCCIPHER_PYCHECK(o) PyObject_TypeCheck((o), gccipher_pytype)
-#define GCCIPHER_CC(o) (((gccipher_pyobj *)(o))->cc)
-#define GCCIPHER_F(o) (((gccipher_pyobj *)(o))->f)
-extern PyObject *gccipher_pywrap(gccipher *);
extern int convgccipher(PyObject *, void *);
-extern int convgcipher(PyObject *, void *);
-
-typedef struct gcipher_pyobj {
- PyObject_HEAD
- unsigned f;
- gcipher *c;
-} gcipher_pyobj;
-
-extern PyTypeObject *gcipher_pytype;
-#define GCIPHER_PYCHECK(o) PyObject_TypeCheck((o), gcipher_pytype)
-#define GCIPHER_C(o) (((gcipher_pyobj *)(o))->c)
-#define GCIPHER_F(o) (((gcipher_pyobj *)(o))->f)
-extern PyObject *gcipher_pywrap(PyObject *, gcipher *, unsigned);
-extern int convgcipher(PyObject *, void *);
+extern PyObject *gccipher_pywrap(gccipher *);
typedef struct gchash_pyobj {
PyHeapTypeObject ty;
} gchash_pyobj;
extern PyTypeObject *gchash_pytype;
+extern PyObject *sha_pyobj, *has160_pyobj;
#define GCHASH_PYCHECK(o) PyObject_TypeCheck((o), gchash_pytype)
#define GCHASH_CH(o) (((gchash_pyobj *)(o))->ch)
-#define GCHASH_F(o) (((gchash_pyobj *)(o))->f)
-extern PyObject *gchash_pywrap(gchash *);
+extern PyObject *ghash_pywrap(PyObject *, ghash *);
extern int convgchash(PyObject *, void *);
-
-typedef struct ghash_pyobj {
- PyObject_HEAD
- unsigned f;
- ghash *h;
-} ghash_pyobj;
-
-extern PyTypeObject *ghash_pytype, *gmhash_pytype;
-extern PyObject *sha_pyobj, *has160_pyobj;
-#define GHASH_PYCHECK(o) PyObject_TypeCheck((o), ghash_pytype)
-#define GHASH_H(o) (((ghash_pyobj *)(o))->h)
-#define GHASH_F(o) (((ghash_pyobj *)(o))->f)
-extern PyObject *ghash_pywrap(PyObject *, ghash *, unsigned);
extern int convghash(PyObject *, void *);
-extern int convgmhash(PyObject *, void *);
-typedef struct gcmac_pyobj {
- PyHeapTypeObject ty;
- gcmac *cm;
-} gcmac_pyobj;
-
-extern PyTypeObject *gcmac_pytype;
-#define GCMAC_PYCHECK(o) PyObject_TypeCheck((o), gcmac_pytype)
-#define GCMAC_CM(o) (((gcmac_pyobj *)(o))->cm)
-#define GCMAC_F(o) (((gcmac_pyobj *)(o))->f)
-extern PyObject *gcmac_pywrap(gcmac *);
extern int convgcmac(PyObject *, void *);
-typedef struct gmac_pyobj {
- PyHeapTypeObject ty;
- unsigned f;
- gmac *m;
-} gmac_pyobj;
-
-extern PyTypeObject *gmac_pytype;
-#define GMAC_PYCHECK(o) PyObject_TypeCheck((o), gmac_pytype)
-#define GMAC_M(o) (((gmac_pyobj *)(o))->m)
-#define GMAC_F(o) (((gmac_pyobj *)(o))->f)
-extern PyObject *gmac_pywrap(PyObject *, gmac *, unsigned);
-extern int convgmac(PyObject *, void *);
-
/*----- Key generation ----------------------------------------------------*/
typedef struct pfilt_pyobj {