17 X509rsaverify \- RSA encryption algorithm
25 .B #include <libsec.h>
27 .ta +\w'\fLRSApriv* \fP'u
29 RSApriv* rsagen(int nlen, int elen, int nrep)
32 mpint* rsaencrypt(RSApub *k, mpint *in, mpint *out)
35 mpint* rsadecrypt(RSApriv *k, mpint *in, mpint *out)
38 RSApub* rsapuballoc(void)
41 void rsapubfree(RSApub*)
44 RSApriv* rsaprivalloc(void)
47 void rsaprivfree(RSApriv*)
50 RSApub* rsaprivtopub(RSApriv*)
53 RSApub* X509toRSApub(uchar *cert, int ncert, char *name, int nname)
56 RSApriv* asn1toRSApriv(uchar *priv, int npriv)
59 void asn1dump(uchar *der, int len)
62 uchar* decodePEM(char *s, char *type, int *len, char **new_s)
65 uchar* X509rsagen(RSApriv *priv, char *subj, ulong valid[2], int *certlen);
68 uchar* X509rsareq(RSApriv *priv, char *subj, int *certlen);
71 char* X509rsaverify(uchar *cert, int ncert, RSApub *pk)
74 RSA is a public key encryption algorithm. The owner of a key publishes
75 the public part of the key:
80 mpint *n; /* modulus */
81 mpint *ek; /* exp (encryption key) */
85 This part can be used for encrypting data (with
87 to be sent to the owner.
88 The owner decrypts (with
90 using his private key:
96 mpint *dk; /* exp (decryption key) */
98 /* precomputed crt values */
101 mpint *kp; /* k mod p-1 */
102 mpint *kq; /* k mod q-1 */
103 mpint *c2; /* for converting residues to number */
107 Keys are generated using
110 takes both bit length of the modulus, the bit length of the
111 public key exponent, and the number of repetitions of the Miller-Rabin
112 primality test to run. If the latter is 0, it does the default number
115 returns a newly allocated structure containing both
116 public and private keys.
118 returns a newly allocated copy of the public key
119 corresponding to the private key.
129 are provided to aid in user provided key I/O.
135 returns the public key and, if
137 is not nil, the CN part of the Distinguished Name of the
138 certificate's Subject.
139 (This is conventionally a userid or a host DNS name.)
140 No verification is done of the certificate signature; the
141 caller should check the fingerprint,
143 against a table or check the certificate by other means.
144 X.509 certificates are often stored in PEM format; use
146 to convert to binary before computing the fingerprint or calling
148 For the special case of
149 certificates signed by a known trusted key
150 (in a single step, without certificate chains),
152 checks the signature on
154 It returns nil if successful, else an error string.
157 creates a self-signed X.509 certificate, given an RSA keypair
159 a issuer/subject string
161 and the starting and ending validity dates,
163 Length of the allocated binary certificate is stored in
165 The subject line is conventionally of the form
168 C=US ST=NJ L=07922 O=Lucent OU='Bell Labs' CN=Eric
171 using the quoting conventions of
177 converts an ASN1 formatted RSA private key into the corresponding
182 prints an ASN1 object to standard output.
185 takes a zero terminated string,
187 and decodes the PEM (privacy-enhanced mail) formatted section for
190 If successful, it returns
192 storage containing the decoded section,
193 which the caller must free,
196 to its decoded length.
204 is set to the first character beyond the