aboutsummaryrefslogtreecommitdiff
path: root/src/libsec/port/x509.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsec/port/x509.c')
-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