aboutsummaryrefslogtreecommitdiff
path: root/src/libsec
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-02-13 18:35:11 +0000
committerrsc <devnull@localhost>2005-02-13 18:35:11 +0000
commit74fc94d47e68684567f16d3d09b822cdad721e4a (patch)
tree6a499b846842d70d2aa08c0e17059c54865d2f2b /src/libsec
parent039b8c9af0866a5a6607cbdd992b586896d48cdc (diff)
downloadplan9port-74fc94d47e68684567f16d3d09b822cdad721e4a.tar.gz
plan9port-74fc94d47e68684567f16d3d09b822cdad721e4a.tar.bz2
plan9port-74fc94d47e68684567f16d3d09b822cdad721e4a.zip
add dsa x509
Diffstat (limited to 'src/libsec')
-rw-r--r--src/libsec/port/x509.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/libsec/port/x509.c b/src/libsec/port/x509.c
index a37b64af..f204ca6f 100644
--- a/src/libsec/port/x509.c
+++ b/src/libsec/port/x509.c
@@ -1934,6 +1934,68 @@ errret:
return nil;
}
+/*
+ * DSAPrivateKey ::= SEQUENCE{
+ * version Version,
+ * p INTEGER,
+ * q INTEGER,
+ * g INTEGER, -- alpha
+ * pub_key INTEGER, -- key
+ * priv_key INTEGER, -- secret
+ * }
+ */
+static DSApriv*
+decode_dsaprivkey(Bytes* a)
+{
+ int version;
+ Elem e;
+ Elist *el;
+ mpint *mp;
+ DSApriv* key;
+
+ key = dsaprivalloc();
+ if(decode(a->data, a->len, &e) != ASN_OK)
+ goto errret;
+ if(!is_seq(&e, &el) || elistlen(el) != 6)
+ goto errret;
+version=-1;
+ if(!is_int(&el->hd, &version) || version != 0)
+{
+fprint(2, "version %d\n", version);
+ goto errret;
+ }
+
+ el = el->tl;
+ key->pub.p = mp = asn1mpint(&el->hd);
+ if(mp == nil)
+ goto errret;
+
+ el = el->tl;
+ key->pub.q = mp = asn1mpint(&el->hd);
+ if(mp == nil)
+ goto errret;
+
+ el = el->tl;
+ key->pub.alpha = mp = asn1mpint(&el->hd);
+ if(mp == nil)
+ goto errret;
+
+ el = el->tl;
+ key->pub.key = mp = asn1mpint(&el->hd);
+ if(mp == nil)
+ goto errret;
+
+ el = el->tl;
+ key->secret = mp = asn1mpint(&el->hd);
+ if(mp == nil)
+ goto errret;
+
+ return key;
+errret:
+ dsaprivfree(key);
+ return nil;
+}
+
static mpint*
asn1mpint(Elem *e)
{
@@ -1984,6 +2046,18 @@ asn1toRSApriv(uchar *kd, int kn)
return key;
}
+DSApriv*
+asn1toDSApriv(uchar *kd, int kn)
+{
+ Bytes *b;
+ DSApriv *key;
+
+ b = makebytes(kd, kn);
+ key = decode_dsaprivkey(b);
+ freebytes(b);
+ return key;
+}
+
/*
* digest(CertificateInfo)
* Our ASN.1 library doesn't return pointers into the original