blob: 2fc75ac64f5b559f9ec0feb98b8db607a105dd35 [file] [log] [blame]
rsccfa37a72004-04-10 18:53:55 +00001.TH ELGAMAL 3
2.SH NAME
3eggen, egencrypt, egdecrypt, egsign, egverify, egpuballoc, egpubfree, egprivalloc, egprivfree, egsigalloc, egsigfree, egprivtopub - elgamal encryption
4.SH SYNOPSIS
5.B #include <u.h>
6.br
7.B #include <libc.h>
8.br
9.B #include <mp.h>
10.br
11.B #include <libsec.h>
12.PP
13.B
14EGpriv* eggen(int nlen, int nrep)
15.PP
16.B
17mpint* egencrypt(EGpub *k, mpint *in, mpint *out)
18.PP
19.B
20mpint* egdecrypt(EGpriv *k, mpint *in, mpint *out)
21.PP
22.B
23EGsig* egsign(EGpriv *k, mpint *m)
24.PP
25.B
26int egverify(EGpub *k, EGsig *sig, mpint *m)
27.PP
28.B
29EGpub* egpuballoc(void)
30.PP
31.B
32void egpubfree(EGpub*)
33.PP
34.B
35EGpriv* egprivalloc(void)
36.PP
37.B
38void egprivfree(EGpriv*)
39.PP
40.B
41EGsig* egsigalloc(void)
42.PP
43.B
44void egsigfree(EGsig*)
45.PP
46.B
47EGpub* egprivtopub(EGpriv*)
48.SH DESCRIPTION
49.PP
50Elgamal is a public key encryption and signature algorithm. The owner of a key publishes
51the public part of the key:
52.EX
53 struct EGpub
54 {
55 mpint *p; // modulus
56 mpint *alpha; // generator
57 mpint *key; // (encryption key) alpha**secret mod p
58 };
59.EE
60This part can be used for encrypting data (with
61.IR egencrypt )
62to be sent to the owner.
63The owner decrypts (with
64.IR egdecrypt )
65using his private key:
66.EX
67 struct EGpriv
68 {
69 EGpub pub;
70 mpint *secret; // (decryption key)
71 };
72.EE
73.PP
74Keys are generated using
75.IR eggen .
76.I Eggen
77takes both bit length of the modulus
78and the number of repetitions of the Miller-Rabin
79primality test to run. If the latter is 0, it does the default number
80of rounds.
81.I Egprivtopub
82returns a newly allocated copy of the public key
83corresponding to the private key.
84.PP
85The routines
86.IR egpuballoc ,
87.IR egpubfree ,
88.IR egprivalloc ,
89and
90.I egprivfree
91are provided to manage key storage.
92.PP
93.I Egsign
94signs message
95.I m
96using a private key
97.I k
98yielding a
99.EX
100 struct EGsig
101 {
102 mpint *r, *s;
103 };
104.EE
105.I Egverify
106returns 0 if the signature is valid and \-1 if not.
107.PP
108The routines
109.I egsigalloc
110and
111.I egsigfree
112are provided to manage signature storage.
113.SH SOURCE
rscc3674de2005-01-11 17:37:33 +0000114.B \*9/src/libsec
rsccfa37a72004-04-10 18:53:55 +0000115.SH SEE ALSO
rscbf8a59f2004-04-11 03:42:27 +0000116.IR mp (3),
117.IR aes (3),
118.IR blowfish (3),
119.IR des (3),
120.IR dsa (3),
121.IR rc4 (3),
122.IR rsa (3),
123.IR sechash (3),
124.IR prime (3),
125.IR rand (3)