1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
.TH ELGAMAL 2
.SH NAME
eggen, egencrypt, egdecrypt, egsign, egverify, egalloc, egfree, egpuballoc, egpubfree, egprivalloc, egprivfree, egsigalloc, egsigfree, egprivtopub - elgamal encryption
.SH SYNOPSIS
.B #include <u.h>
.br
.B #include <libc.h>
.br
.B #include <mp.h>
.br
.B #include <libsec.h>
.PP
.B
EGpriv* eggen(int nlen, int nrep)
.PP
.B
mpint* egencrypt(EGpub *k, mpint *in, mpint *out)
.PP
.B
mpint* egdecrypt(EGpriv *k, mpint *in, mpint *out)
.PP
.B
EGsig* egsign(EGpriv *k, mpint *m)
.PP
.B
int egverify(EGpub *k, EGsig *sig, mpint *m)
.PP
.B
EGpub* egpuballoc(void)
.PP
.B
void egpubfree(EGpub*)
.PP
.B
EGpriv* egprivalloc(void)
.PP
.B
void egprivfree(EGpriv*)
.PP
.B
EGsig* egsigalloc(void)
.PP
.B
void egsigfree(EGsig*)
.PP
.B
EGpub* egprivtopub(EGpriv*)
.SH DESCRIPTION
.PP
The corresponding keys for the ElGamal algorithm are:
.EX
struct EGpub
{
mpint *p; // modulus
mpint *alpha; // generator
mpint *key; // (encryption key) alpha**secret mod p
};
.EE
and
.EX
struct EGpriv
{
EGpub pub;
mpint *secret; // (decryption key)
};
.EE
.I Egsign
signs message
.I m
using a private key
.I k
yielding a
.EX
struct EGsig
{
mpint *r, *s;
};
.EE
.I Egverify
returns 0 if the signature is valid and \-1 if not.
.SH SOURCE
.B /sys/src/libsec
.SH SEE ALSO
.IR mp (2),
.IR aes (2),
.IR blowfish (2),
.IR des (2),
.IR rc4 (2),
.IR rsa (2),
.IR sechash (2),
.IR prime (2),
.IR rand (2)
|