chiark / gitweb /
pubkey.c, catacomb/__init__.py: Add bindings for Hamburg's X448.
[catacomb-python] / catacomb / __init__.py
index 115e8fe785cec67af3ce5d46b0480ad4866cea08..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,31 @@ 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
+  def verify(me, msg, sig):
+    return ed25519_verify(me.pub, msg, sig)
+
+class Ed25519Priv (Ed25519Pub):
+  def __init__(me, priv):
+    me.priv = priv
+    Ed25519Pub.__init__(me, ed25519_pubkey(priv))
+  def sign(me, msg):
+    return ed25519_sign(me.priv, msg, pub = me.pub)
+  @classmethod
+  def generate(cls, rng = rand):
+    return cls(rng.block(ED25519_KEYSZ))
+
 ###--------------------------------------------------------------------------
 ### Built-in named curves and prime groups.