Main Page Modules Data Structures File List Data Fields Globals Related Pages

# beecrypt/elgamal.c File Reference

ElGamal signature scheme, code. More...

`#include "system.h"`
`#include "elgamal.h"`
`#include "dldp.h"`
`#include "mp32.h"`
`#include "debug.h"`

Go to the source code of this file.

## Functions

int | elgv1sign (const mp32barrett *p, const mp32barrett *n, const mp32number *g, randomGeneratorContext *rgc, const mp32number *hm, const mp32number *x, mp32number *r, mp32number *s)
int | elgv1vrfy (const mp32barrett *p, const mp32barrett *n, const mp32number *g, const mp32number *hm, const mp32number *y, const mp32number *r, const mp32number *s)
int | elgv3sign (const mp32barrett *p, const mp32barrett *n, const mp32number *g, randomGeneratorContext *rgc, const mp32number *hm, const mp32number *x, mp32number *r, mp32number *s)
int | elgv3vrfy (const mp32barrett *p, const mp32barrett *n, const mp32number *g, const mp32number *hm, const mp32number *y, const mp32number *r, const mp32number *s)

## Detailed Description

ElGamal signature scheme, code.

This code implements two of the six variants described:

- ElGamal Signature variant 1: (i.e. the standard version)
  - Signing equation:
    - r = g^k mod p and
    - s = inv(k) * (h(m) - x*r) mod (p-1)
  - Verifying equation:
    - check 1 <= r <= (p-1)
    - v1 = g^h(m) mod p
    - v2 = y^r * r^s mod p
    - check v1 == v2
  - Simultaneous multiple exponentiation verification:
    - y^r * r^s * g^(p-1-h(m)) mod p = 1 or (the former is probably faster)
    - y^r * r^s * inv(g)^h(m) mod p = 1

- ElGamal Signature variant 3: signing is simpler, because no inverse has to be calculated
  - Signing equation:
    - r = g^k mod p and
    - s = x*r + k*h(m) mod (p-1)
  - Verifying equation:
    - check 1 <= r <= (p-1)
    - v1 = g^s mod p
    - v2 = y^r * r^h(m) mod p
  - Simultaneous multiple exponentiation verification:
    - y^r * r^h(m) * g^(p-1-s) mod p = 1 (one of the exponents is significantly smaller, i.e. h(m))

For more information on this algorithm, see: "Handbook of Applied Cryptography" 11.5.2 "The ElGamal signature scheme", p. 454-459

Definition in file elgamal.c.

## Function Documentation

int elgv1sign | ( | const mp32barrett * | p,
|  | const mp32barrett * | n,
|  | const mp32number * | g,
|  | randomGeneratorContext * | ,
|  | const mp32number * | hm,
|  | const mp32number * | x,
|  | mp32number * | r,
|  | mp32number * | s
| ) |

| Definition at line 63 of file elgamal.c. References mp32number::data, mp32barrett::modl, mp32add, mp32baddmod_w, mp32bmulmod_w, mp32bpowmod_w, mp32brndinv_w, mp32neg, mp32nfree, mp32nsize, mp32number::size, mp32barrett::size, and uint32.

int elgv1vrfy | ( | const mp32barrett * | p,
|  | const mp32barrett * | n,
|  | const mp32number * | g,
|  | const mp32number * | hm,
|  | const mp32number * | y,
|  | const mp32number * | r,
|  | const mp32number * | s
| ) |

| Definition at line 100 of file elgamal.c. References mp32number::data, mp32barrett::modl, mp32bmulmod_w, mp32bpowmod_w, mp32eq, mp32gex, mp32z, mp32number::size, mp32barrett::size, and uint32.

int elgv3sign | ( | const mp32barrett * | p,
|  | const mp32barrett * | n,
|  | const mp32number * | g,
|  | randomGeneratorContext * | ,
|  | const mp32number * | hm,
|  | const mp32number * | x,
|  | mp32number * | r,
|  | mp32number * | s
| ) |

| Definition at line 144 of file elgamal.c. References mp32number::data, mp32baddmod_w, mp32bmulmod_w, mp32bpowmod_w, mp32brnd_w, mp32nfree, mp32nsize, mp32number::size, mp32barrett::size, and uint32.

int elgv3vrfy | ( | const mp32barrett * | p,
|  | const mp32barrett * | n,
|  | const mp32number * | g,
|  | const mp32number * | hm,
|  | const mp32number * | y,
|  | const mp32number * | r,
|  | const mp32number * | s
| ) |

| Definition at line 177 of file elgamal.c. References mp32number::data, mp32barrett::modl, mp32bmulmod_w, mp32bpowmod_w, mp32eq, mp32gex, mp32z, mp32number::size, mp32barrett::size, and uint32.