219 lines · 4.3 KB · Text
RawDownload
.TH RSA 2.SH NAMEasn1dump,asn1toRSApriv,decodePEM,rsadecrypt,rsaencrypt,rsagen,rsaprivalloc,rsaprivfree,rsaprivtopub,rsapuballoc,rsapubfree,X509toRSApub,X509gen,X509verify \- RSA encryption algorithm.SH SYNOPSIS.B #include <u.h>.br.B #include <libc.h>.br.B #include <mp.h>.br.B #include <libsec.h>.PP.ta +\w'\fLRSApriv* \fP'u.BRSApriv*	rsagen(int nlen, int elen, int nrep).PP.Bmpint*	rsaencrypt(RSApub *k, mpint *in, mpint *out).PP.Bmpint*	rsadecrypt(RSApriv *k, mpint *in, mpint *out).PP.BRSApub*	rsapuballoc(void).PP.Bvoid	rsapubfree(RSApub*).PP.BRSApriv*	rsaprivalloc(void).PP.Bvoid	rsaprivfree(RSApriv*).PP.BRSApub*	rsaprivtopub(RSApriv*).PP.BRSApub*	X509toRSApub(uchar *cert, int ncert, char *name, int nname).PP.BRSApriv*	asn1toRSApriv(uchar *priv, int npriv).PP.Bvoid		asn1dump(uchar *der, int len).PP.Buchar*	decodePEM(char *s, char *type, int *len, char **new_s).PP.Buchar*	X509gen(RSApriv *priv, char *subj, ulong valid[2], int *certlen);.PP.Buchar*	X509req(RSApriv *priv, char *subj, int *certlen);.PP.Bchar*	X509verify(uchar *cert, int ncert, RSApub *pk).DT.SH DESCRIPTIONRSA is a public key encryption algorithm.  The owner of a key publishesthe public part of the key:.IP.EXstruct RSApub{	mpint	*n;	/* modulus */	mpint	*ek;	/* exp (encryption key) */};.EE.LPThis part can be used for encrypting data (with.IR rsaencrypt )to be sent to the owner.The owner decrypts (with.IR rsadecrypt )using his private key:.IP.EXstruct RSApriv{	RSApub	pub;	mpint	*dk;	/* exp (decryption key) */ 	/* precomputed crt values */	mpint	*p;	mpint	*q;	mpint	*kp;	/* k mod p-1 */	mpint	*kq;	/* k mod q-1 */	mpint	*c2;	/* for converting residues to number */};.EE.PPKeys are generated using.IR rsagen ..I Rsagentakes both bit length of the modulus, the bit length of thepublic key exponent, and the number of repetitions of the Miller-Rabinprimality test to run.  If the latter is 0, it does the default numberof rounds..I Rsagenreturns a newly allocated structure containing bothpublic and private keys..I Rsaprivtopubreturns a newly allocated copy of the public keycorresponding to the private key..PPThe routines.IR rsaalloc ,.IR rsafree ,.IR rsapuballoc ,.IR rsapubfree ,.IR rsaprivalloc ,and.I rsaprivfreeare provided to aid in user provided key I/O..PPGiven a binary X.509.IR cert ,the routine.I X509toRSApubreturns the public key and, if.I nameis not nil, the CN part of the Distinguished Name of thecertificate's Subject.(This is conventionally a userid or a host DNS name.)No verification is done of the certificate signature;  thecaller should check the fingerprint,.IR sha1(cert) ,against a table or check the certificate by other means.X.509 certificates are often stored in PEM format; use.I dec64to convert to binary before computing the fingerprint or calling.IR X509toRSApub .For the special case ofcertificates signed by a known trusted key(in a single step, without certificate chains),.I X509verifychecks the signature on.IR cert .It returns nil if successful, else an error string..PP.I X509gencreates a self-signed X.509 certificate, given an RSA keypair.IR priv ,a issuer/subject string.IR subj ,and the starting and ending validity dates,.IR valid .Length of the allocated binary certificate is stored in.IR certlen .The subject line is conventionally of the form.IP.EXC=US ST=NJ L=07922 O=Lucent OU='Bell Labs' CN=Eric.EE.LPusing the quoting conventions of.I tokenizein.IR getfields (2)..PP.I Asn1toRSAprivconverts an ASN1 formatted RSA private key into the corresponding.B RSAprivstructure..PP.I Asn1dumpprints an ASN1 object to standard output..PP.I DecodePEMtakes a zero terminated string,.IR s ,and decodes the PEM (privacy-enhanced mail) formatted section for.I typewithin it.If successful, it returns.IR malloc edstorage containing the decoded section,which the caller must free,and sets.BI * lento its decoded length.Otherwise.B nilis returned and.BI * lenis undefined.If not nil,.I new_sis set to the first character beyond the.I typesection..SH SOURCE.B /sys/src/libsec.SH SEE ALSO.IR mp (2),.IR aes (2),.IR blowfish (2),.IR des (2),.IR dsa (2),.IR elgamal (2),.IR rc4 (2),.IR sechash (2),.IR prime (2),.IR rand (2),.IR rsa (8)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t