algorithms.c: Set `hashsz', `tagsz', and `name' properties on MAC keys.
[catacomb-python] / algorithms.c
index 071894a..57a41d7 100644 (file)
@@ -2309,6 +2309,22 @@ static const PyGetSetDef gcmac_pygetset[] = {
   { 0 }
 };
 
+static PyObject *gmget_name(PyObject *me, void *hunoz)
+  { return (TEXT_FROMSTR(GMAC_M(me)->ops->c->name)); }
+
+static PyObject *gmget_hashsz(PyObject *me, void *hunoz)
+  { return (PyInt_FromLong(GMAC_M(me)->ops->c->hashsz)); }
+#define gmget_tagsz gmget_hashsz
+
+static const PyGetSetDef gmac_pygetset[] = {
+#define GETSETNAME(op, name) gm##op##_##name
+  GET  (hashsz,        "M.hashsz -> MAC output size")
+  GET  (tagsz,         "M.tagsz -> MAC output size")
+  GET  (name,          "M.name -> name of this kind of MAC")
+#undef GETSETNAME
+  { 0 }
+};
+
 static const PyTypeObject gcmac_pytype_skel = {
   PyVarObject_HEAD_INIT(0, 0)          /* Header */
   "GCMAC",                             /* @tp_name@ */
@@ -2392,7 +2408,7 @@ static const PyTypeObject gmac_pytype_skel = {
   0,                                   /* @tp_iternext@ */
   0,                                   /* @tp_methods@ */
   0,                                   /* @tp_members@ */
-  0,                                   /* @tp_getset@ */
+  PYGETSET(gmac),                      /* @tp_getset@ */
   0,                                   /* @tp_base@ */
   0,                                   /* @tp_dict@ */
   0,                                   /* @tp_descr_get@ */
@@ -2632,6 +2648,20 @@ static const PyGetSetDef poly1305cls_pygetset[] = {
   { 0 }
 };
 
+static PyObject *poly1305get_name(PyObject *me, void *hunoz)
+  { RETURN_OBJ(((PyHeapTypeObject *)poly1305key_pytype)->ht_name); }
+
+static PyObject *poly1305get_tagsz(PyObject *me, void *hunoz)
+  { return (PyInt_FromLong(16)); }
+
+static const PyGetSetDef poly1305_pygetset[] = {
+#define GETSETNAME(op, name) poly1305##op##_##name
+  GET  (tagsz,         "PK.tagsz -> MAC output size")
+  GET  (name,          "PK.name -> name of this kind of MAC")
+#undef GETSETNAME
+  { 0 }
+};
+
 static const PyMethodDef poly1305hash_pymethods[] = {
 #define METHNAME(name) polymeth_##name
   NAMETH(copy,         "P.copy() -> PP")
@@ -2734,7 +2764,7 @@ static const PyTypeObject poly1305key_pytype_skel = {
   0,                                   /* @tp_iternext@ */
   0,                                   /* @tp_methods@ */
   0,                                   /* @tp_members@ */
-  0,                                   /* @tp_getset@ */
+  PYGETSET(poly1305),                  /* @tp_getset@ */
   0,                                   /* @tp_base@ */
   0,                                   /* @tp_dict@ */
   0,                                   /* @tp_descr_get@ */