m2crypto patch - DSA pub key handling
Dan Berger <[email protected]>
| Newsgroups | gmane.comp.python.cryptography |
|---|---|
| Message-ID | <[email protected]> |
I've added the ability to explicitly set the public key member of a DSA_pub key object (I needed to reconstruct a DSA key from it's parameters and pub key, as that's how they're being stored in a system I'm interfacing with). The attached patch builds on Igor Belyi's patch posted to this list 12 April, 2004. Cheers. -- ...Dan Berger [[email protected]] Department of Computer Science Surge Building, Room 357 University of California, Riverside http://www.cs.ucr.edu/~dberger Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. - Albert Einstein
m2crypto.patch
(text/x-patch, 1.8 KB)
Only in m2crypto-0.13: build
diff -ur m2crypto-0.13-orig/M2Crypto/DSA.py m2crypto-0.13/M2Crypto/DSA.py
--- m2crypto-0.13-orig/M2Crypto/DSA.py 2004-07-29 17:20:28.000000000 -0700
+++ m2crypto-0.13/M2Crypto/DSA.py 2004-07-30 09:23:15.803341824 -0700
@@ -150,6 +150,9 @@
else:
self.__dict__[name] = value
+ def set_pub_key(self, pub):
+ m2.dsa_set_pub_key(self.dsa, pub)
+
def sign(self, digest):
raise DSAError, 'DSA_pub object can not be used for signing'
diff -ur m2crypto-0.13-orig/SWIG/_dsa.i m2crypto-0.13/SWIG/_dsa.i
--- m2crypto-0.13-orig/SWIG/_dsa.i 2004-07-30 09:33:13.826897188 -0700
+++ m2crypto-0.13/SWIG/_dsa.i 2004-07-30 09:23:10.845752391 -0700
@@ -174,6 +174,33 @@
return Py_None;
}
+PyObject *dsa_set_pub_key(DSA *dsa, PyObject *value) {
+ BIGNUM *bn;
+ const void *vbuf;
+ int vlen;
+
+#if PYTHON_API_VERSION >= 1009
+ if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1)
+ return NULL;
+#else /* assume PYTHON_API_VERSION == 1007 */
+ if (!PyString_Check(value)) {
+ PyErr_SetString(PyExc_TypeError, "expected a string object");
+ return NULL;
+ }
+ vlen = PyString_Size(value);
+ vbuf = (const void *)PyString_AsString(value);
+#endif
+ if (!(bn = BN_mpi2bn((unsigned char *)vbuf, vlen, NULL))) {
+ PyErr_SetString(_dsa_err, ERR_reason_error_string(ERR_get_error()));
+ return NULL;
+ }
+ if (dsa->pub_key)
+ BN_free(dsa->pub_key);
+ dsa->pub_key = bn;
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
DSA *dsa_read_params(BIO *f, PyObject *pyfunc) {
DSA *ret;
@@ -410,7 +437,7 @@
}
int dsa_check_pub_key(DSA *dsa) {
- return dsa->pub_key;
+ return (dsa->pub_key != NULL);
}
int dsa_keylen(DSA *dsa) {
signature.asc
(application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iD8DBQBBCrlHhHyVxVGhKFYRAg+wAKCISb37tk1AxiMrqm1kq8SshDP00wCgwRHP SD7xYBITkfZE5CMcF1tBamU= =j9KO -----END PGP SIGNATURE-----