telgamal.3 - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       telgamal.3 (2160B)
       ---
            1 .TH ELGAMAL 3
            2 .SH NAME
            3 eggen, 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
           14 EGpriv*        eggen(int nlen, int nrep)
           15 .PP
           16 .B
           17 mpint*        egencrypt(EGpub *k, mpint *in, mpint *out)
           18 .PP
           19 .B
           20 mpint*        egdecrypt(EGpriv *k, mpint *in, mpint *out)
           21 .PP
           22 .B
           23 EGsig*        egsign(EGpriv *k, mpint *m)
           24 .PP
           25 .B
           26 int                egverify(EGpub *k, EGsig *sig, mpint *m)
           27 .PP
           28 .B
           29 EGpub*        egpuballoc(void)
           30 .PP
           31 .B
           32 void                egpubfree(EGpub*)
           33 .PP
           34 .B
           35 EGpriv*        egprivalloc(void)
           36 .PP
           37 .B
           38 void                egprivfree(EGpriv*)
           39 .PP
           40 .B
           41 EGsig*        egsigalloc(void)
           42 .PP
           43 .B
           44 void                egsigfree(EGsig*)
           45 .PP
           46 .B
           47 EGpub*        egprivtopub(EGpriv*)
           48 .SH DESCRIPTION
           49 .PP
           50 Elgamal is a public key encryption and signature algorithm.  The owner of a key publishes
           51 the 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
           60 This part can be used for encrypting data (with
           61 .IR egencrypt )
           62 to be sent to the owner.
           63 The owner decrypts (with
           64 .IR egdecrypt )
           65 using his private key:
           66 .EX
           67         struct EGpriv
           68         {
           69                 EGpub        pub;
           70                 mpint        *secret; // (decryption key)
           71         };
           72 .EE
           73 .PP
           74 Keys are generated using
           75 .IR eggen .
           76 .I Eggen
           77 takes both bit length of the modulus
           78 and the number of repetitions of the Miller-Rabin
           79 primality test to run.  If the latter is 0, it does the default number
           80 of rounds.
           81 .I Egprivtopub
           82 returns a newly allocated copy of the public key
           83 corresponding to the private key.
           84 .PP
           85 The routines
           86 .IR egpuballoc ,
           87 .IR egpubfree ,
           88 .IR egprivalloc ,
           89 and
           90 .I egprivfree
           91 are provided to manage key storage.
           92 .PP
           93 .I Egsign
           94 signs message
           95 .I m
           96 using a private key
           97 .I k
           98 yielding a
           99 .EX
          100         struct EGsig
          101         {
          102                 mpint        *r, *s;
          103         };
          104 .EE
          105 .I Egverify
          106 returns 0 if the signature is valid and \-1 if not.
          107 .PP
          108 The routines
          109 .I egsigalloc
          110 and
          111 .I egsigfree
          112 are provided to manage signature storage.
          113 .SH SOURCE
          114 .B \*9/src/libsec
          115 .SH SEE ALSO
          116 .MR mp (3) ,
          117 .MR aes (3) ,
          118 .MR blowfish (3) ,
          119 .MR des (3) ,
          120 .MR dsa (3) ,
          121 .MR rc4 (3) ,
          122 .MR rsa (3) ,
          123 .MR sechash (3) ,
          124 .MR prime (3) ,
          125 .MR rand (3)