{ 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@ */
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@ */
{ 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")
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@ */
"""
Check hash class HCLS.
- If NEED_BUFSZ is false, then don't insist that HCLS have working `bufsz',
- `name', or `hashsz' attributes. This test is mostly reused for MACs,
- which don't have these attributes.
+ If NEED_BUFSZ is false, then don't insist that HCLS has a working `bufsz'
+ attribute. This test is mostly reused for MACs, which don't have this
+ attribute.
"""
## Check the class properties.
- if need_bufsz:
- me.assertEqual(type(hcls.name), str)
- me.assertEqual(type(hcls.bufsz), int)
- me.assertEqual(type(hcls.hashsz), int)
+ me.assertEqual(type(hcls.name), str)
+ if need_bufsz: me.assertEqual(type(hcls.bufsz), int)
+ me.assertEqual(type(hcls.hashsz), int)
## Set some initial values.
m = T.span(131)
h = hcls().hash(m).done()
## Check that hash length comes out right.
- if need_bufsz: me.assertEqual(len(h), hcls.hashsz)
+ me.assertEqual(len(h), hcls.hashsz)
## Check that we get the same answer if we split the message up.
me.assertEqual(h, hcls().hash(m[0:73]).hash(m[73:131]).done())
## Check the `check' method.
me.assertTrue(hcls().hash(m).check(h))
- me.assertFalse(hcls().hash(m).check(h ^ len(h)*C.bytes("aa")))
+ me.assertFalse(hcls().hash(m).check(h ^ hcls.hashsz*C.bytes("aa")))
## Check the menagerie of random hashing methods.
def mkhash(_):
## Test hashing.
k = T.span(mcls.keysz.default)
key = mcls(k)
+ me.assertEqual(key.hashsz, key.tagsz)
me.check_hash(key, need_bufsz = False)
## Check that bad key lengths are rejected.
t = key(u).hash(m).done()
## Check the key properties.
+ me.assertEqual(key.name, "poly1305")
+ me.assertEqual(key.tagsz, 16)
+ me.assertEqual(key.tagsz, 16)
me.assertEqual(len(t), 16)
## Check that we get the same answer if we split the message up.