16 X509verify \- RSA encryption algorithm
24 .B #include <libsec.h>
27 RSApriv* rsagen(int nlen, int elen, int nrep)
30 mpint* rsaencrypt(RSApub *k, mpint *in, mpint *out)
33 mpint* rsadecrypt(RSApriv *k, mpint *in, mpint *out)
36 RSApub* rsapuballoc(void)
39 void rsapubfree(RSApub*)
42 RSApriv* rsaprivalloc(void)
45 void rsaprivfree(RSApriv*)
48 RSApub* rsaprivtopub(RSApriv*)
51 RSApub* X509toRSApub(uchar *cert, int ncert, char *name, int nname)
54 RSApriv* asn1toRSApriv(uchar *priv, int npriv)
57 void asn1dump(uchar *der, int len)
60 uchar* decodepem(char *s, char *type, int *len)
63 uchar* X509gen(RSApriv *priv, char *subj, ulong valid[2], int *certlen);
66 uchar* X509req(RSApriv *priv, char *subj, int *certlen);
69 char* X509verify(uchar *cert, int ncert, RSApub *pk)
72 RSA is a public key encryption algorithm. The owner of a key publishes
73 the public part of the key:
78 mpint *ek; // exp (encryption key)
81 This part can be used for encrypting data (with
83 to be sent to the owner.
84 The owner decrypts (with
86 using his private key:
91 mpint *dk; // exp (decryption key)
93 // precomputed crt values
96 mpint *kp; // k mod p-1
97 mpint *kq; // k mod q-1
98 mpint *c2; // for converting residues to number
102 Keys are generated using
105 takes both bit length of the modulus, the bit length of the
106 public key exponent, and the number of repetitions of the Miller-Rabin
107 primality test to run. If the latter is 0, it does the default number
110 returns a newly allocated structure containing both
111 public and private keys.
113 returns a newly allocated copy of the public key
114 corresponding to the private key.
124 are provided to aid in user provided key I/O.
130 returns the public key and, if
132 is not nil, the CN part of the Distinguished Name of the
133 certificate's Subject.
134 (This is conventionally a userid or a host DNS name.)
135 No verification is done of the certificate signature; the
136 caller should check the fingerprint,
138 against a table or check the certificate by other means.
139 X.509 certificates are often stored in PEM format; use
141 to convert to binary before computing the fingerprint or calling
143 For the special case of
144 certificates signed by a known trusted key
145 (in a single step, without certificate chains)
147 checks the signature on
149 It returns nil if successful, else an error string.
152 creates a self-signed X.509 certificate, given an RSA keypair
154 a issuer/subject string
156 and the starting and ending validity dates,
158 Length of the allocated binary certificate is stored in
160 The subject line is conventionally of the form
162 "C=US ST=NJ L=07922 O=Lucent OU='Bell Labs' CN=Eric"
164 using the quoting conventions of
168 converts an ASN1 formatted RSA private key into the corresponding
173 prints an ASN1 object to standard output.
176 takes a zero terminated string,
178 and decodes the PEM (privacy-enhanced mail) formatted section for
181 If successful, it returns the decoded section and sets
183 to its decoded length.
190 .B /usr/local/plan9/src/libsec