chiark / gitweb /
pubkey.c, catacomb/__init__.py: Add bindings for Hamburg's X448.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 26 Apr 2017 10:53:05 +0000 (11:53 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 3 May 2017 11:51:27 +0000 (12:51 +0100)
catacomb-python.h
catacomb.c
catacomb/__init__.py
pubkey.c

index 41c52924a972d4793c27d1c84db5182390fdd2bf..d7e254355dfb79fcd42dca3caaba556b9a883a85 100644 (file)
@@ -88,6 +88,7 @@
 #include <catacomb/bintab.h>
 #include <catacomb/dsa.h>
 #include <catacomb/x25519.h>
+#include <catacomb/x448.h>
 #include <catacomb/ed25519.h>
 
 #include <catacomb/gf.h>
index d64a16e77e4a6c8a1448415430121f668288ddbb..9c83c9dbe29877bd1b7654123f4362122ee9da36 100644 (file)
@@ -46,6 +46,7 @@ static const struct nameval consts[] = {
   C(KF_BURN), C(KF_OPT),
   C(EC_XONLY), C(EC_YBIT), C(EC_LSB), C(EC_CMPR), C(EC_EXPLY), C(EC_SORT),
   C(X25519_KEYSZ), C(X25519_PUBSZ), C(X25519_OUTSZ),
+  C(X448_KEYSZ), C(X448_PUBSZ), C(X448_OUTSZ),
   C(ED25519_KEYSZ), C(ED25519_PUBSZ), C(ED25519_SIGSZ),
 #define ENTRY(tag, val, str) C(KERR_##tag),
   KEY_ERRORS(ENTRY)
index 9522528ae6b1b930c53a8ec6e02ac6dffba96a28..4c225e7ab2645f52b79d8b657c1b39d84e33f370 100644 (file)
@@ -459,11 +459,15 @@ class _tmp:
 _augment(RSAPriv, _tmp)
 
 ###--------------------------------------------------------------------------
-### Bernstein's elliptic curve crypto.
+### Bernstein's elliptic curve crypto and related schemes.
 
 X25519_BASE = \
   bytes('0900000000000000000000000000000000000000000000000000000000000000')
 
+X448_BASE = \
+  bytes('05000000000000000000000000000000000000000000000000000000'
+        '00000000000000000000000000000000000000000000000000000000')
+
 Z128 = bytes('00000000000000000000000000000000')
 
 class _BoxyPub (object):
@@ -495,6 +499,15 @@ class X25519Priv (_BoxyPriv, X25519Pub):
   def _op(me, k, X): return x25519(k, X)
   def _hashkey(me, z): return hsalsa20_prf(z, Z128)
 
+class X448Pub (_BoxyPub):
+  _PUBSZ = X448_PUBSZ
+  _BASE = X448_BASE
+
+class X448Priv (_BoxyPriv, X448Pub):
+  _KEYSZ = X448_KEYSZ
+  def _op(me, k, X): return x448(k, X)
+  ##def _hashkey(me, z): return ???
+
 class Ed25519Pub (object):
   def __init__(me, pub):
     me.pub = pub
index 391db319d4106aef59b02335c4a78c15a2fd18e5..5292717f5b4c0804783682a05f4c2876751cbc39 100644 (file)
--- a/pubkey.c
+++ b/pubkey.c
@@ -1118,7 +1118,7 @@ end:
   return (rc);
 }
 
-/*----- X25519 ------------------------------------------------------------*/
+/*----- X25519 and related algorithms -------------------------------------*/
 
 static PyObject *meth_x25519(PyObject *me, PyObject *arg)
 {
@@ -1136,6 +1136,22 @@ end:
   return (0);
 }
 
+static PyObject *meth_x448(PyObject *me, PyObject *arg)
+{
+  const char *k, *p;
+  Py_ssize_t ksz, psz;
+  PyObject *rc = 0;
+  if (!PyArg_ParseTuple(arg, "s#s#:x448", &k, &ksz, &p, &psz)) goto end;
+  if (ksz != X448_KEYSZ) VALERR("bad key length");
+  if (psz != X448_PUBSZ) VALERR("bad public length");
+  rc = bytestring_pywrap(0, X448_OUTSZ);
+  x448((octet *)PyString_AS_STRING(rc),
+       (const octet *)k, (const octet *)p);
+  return (rc);
+end:
+  return (0);
+}
+
 /*----- Ed25519 -----------------------------------------------------------*/
 
 static PyObject *meth_ed25519_pubkey(PyObject *me, PyObject *arg)
@@ -1203,6 +1219,8 @@ static PyMethodDef methods[] = {
 generate(NBITS, [event = pgen_nullev, rng = rand, nsteps = 0]) -> R")
   METH  (x25519,                       "\
 x25519(KEY, PUBLIC) -> SHARED")
+  METH  (x448,                         "\
+x448(KEY, PUBLIC) -> SHARED")
   METH  (ed25519_pubkey,               "\
 ed25519_pubkey(KEY) -> PUBLIC")
   KWMETH(ed25519_sign,                 "\