.TH EC 2
.SH NAME
+secp256r1,
+secp256k1,
+secp384r1,
+ecdominit,
+ecdomfree,
ecassign,
ecadd,
ecmul,
ecverify,
ecpubverify,
ecdsasign,
-ecdsaverify \- elliptic curve cryptography
+ecdsaverify,
+ecencodepub,
+ecdecodepub,
+ecpubfree,
+X509toECpub,
+X509ecdsaverify,
+X509ecdsaverifydigest \- elliptic curve cryptography
.SH SYNOPSIS
.B #include <u.h>
.br
.B #include <libsec.h>
.PP
.B
-void ecassign(ECdomain *dom, ECpoint *old, ECpoint *new);
+void secp256r1(mpint *p, mpint *a, mpint *b, mpint *x, mpint *y, mpint *n, mpint *h)
.PP
.B
-void ecadd(ECdomain *dom, ECpoint *a, ECpoint *b, ECpoint *s);
+void secp256k1(mpint *p, mpint *a, mpint *b, mpint *x, mpint *y, mpint *n, mpint *h)
.PP
.B
-void ecmul(ECdomain *dom, ECpoint *a, mpint *k, ECpoint *s);
+void secp384r1(mpint *p, mpint *a, mpint *b, mpint *x, mpint *y, mpint *n, mpint *h)
.PP
.B
-ECpoint* strtoec(ECdomain *dom, char *s, char **rptr, ECpoint *p);
+void ecdominit(ECdomain *dom, void (*init)(mpint *p, mpint *a, mpint *b, mpint *x, mpint *y, mpint *n, mpint *h))
.PP
.B
-ECpriv* ecgen(ECdomain *dom, ECpriv *p);
+void ecdomfree(ECdomain *dom)
.PP
.B
-int ecverify(ECdomain *dom, ECpoint *p);
+void ecassign(ECdomain *dom, ECpoint *old, ECpoint *new)
.PP
.B
-int ecpubverify(ECdomain *dom, ECpub *p);
+void ecadd(ECdomain *dom, ECpoint *a, ECpoint *b, ECpoint *s)
.PP
.B
-void ecdsasign(ECdomain *dom, ECpriv *priv, uchar *dig, int dlen, mpint *r, mpint *s);
+void ecmul(ECdomain *dom, ECpoint *a, mpint *k, ECpoint *s)
.PP
.B
-int ecdsaverify(ECdomain *dom, ECpub *pub, uchar *dig, int dlen, mpint *r, mpint *s);
+ECpoint* strtoec(ECdomain *dom, char *s, char **rptr, ECpoint *p)
+.PP
+.B
+ECpriv* ecgen(ECdomain *dom, ECpriv *p)
+.PP
+.B
+int ecverify(ECdomain *dom, ECpoint *p)
+.PP
+.B
+int ecpubverify(ECdomain *dom, ECpub *p)
+.PP
+.B
+void ecdsasign(ECdomain *dom, ECpriv *priv, uchar *dig, int dlen, mpint *r, mpint *s)
+.PP
+.B
+int ecdsaverify(ECdomain *dom, ECpub *pub, uchar *dig, int dlen, mpint *r, mpint *s)
+.PP
+.B
+int ecencodepub(ECdomain *dom, ECpub *pub, uchar *data, int len)
+.PP
+.B
+ECpub* ecdecodepub(ECdomain *dom, uchar *data, int len)
+.PP
+.B
+void ecpubfree(ECpub *p);
+.PP
+.B
+ECpub* X509toECpub(uchar *cert, int ncert, char *name, int nname, ECdomain *dom)
+.PP
+.B
+char* X509ecdsaverify(uchar *cert, int ncert, ECdomain *dom, ECpub *pub)
+.PP
+.B
+char* X509ecdsaverifydigest(uchar *sig, int siglen, uchar *edigest, int edigestlen, ECdomain *dom, ECpub *pub)
.DT
.SH DESCRIPTION
These functions implement elliptic curve cryptography.
.B ECpoint
structs.
.PP
+.B ecdominit
+initializes a
+.B ECdomain
+struct and calls the
+.B init
+function such as
+.B secp256r1
+which fills in the parameters of the curve.
+.PP
+.B ecdomfree
+frees the parameters of the curve and zeros the struct. It does
+not free the memory of the struct itself.
+.PP
.BR ecassign ", " ecadd " and " ecmul
are analogous to their counterparts in
.IR mp (2).
writes the signature to
.BR r " and " s
which are assumed to be allocated properly.
+.PP
+.B ecencodepub
+and
+.B ecdecodepub
+handle encoding and decoding of public keys in uncompressed format.
+Note that
+.B ecdecodepub
+also verifies that the public key is valid in the specified domain.
+.PP
+.B ecpubfree
+frees a
+.B ECpub
+structure and its associated members.
+.PP
+Given a binary X.509 cert, the function
+.B X509toECpub
+initializes domain parameters and returns the ECDSA public key. if
+.I name
+is not
+.BR nil ,
+the CN part of the Distinguished Name of the certificate's Subject is returned.
+.B X509ecdsaverify
+and
+.B X509ecdsaverifydigest
+are analogs to the routines described by
+.IR rsa (2).
.SH RETURN VALUE
.B *verify
functions return
.SH SOURCE
.B /sys/src/libsec/port/ecc.c
.SH SEE ALSO
+.IR rsa (2)
+.br
.I
Standards for Efficient Cryptography (SEC) 1: Elliptic Curve Cryptography
- Certicom Research, 2009