/* Author: Pate Williams (c) 1997 Exercise 9.2 "Suppose Alice is using the Schnorr Scheme where q = 1201, p = 122503, t = 10, and alpha = 11538. (a) Verify that alpha has order q in Z_p*. (b) Suppose that Alice's secret exponent is a = 357. Compute v. (c) Suppose that k = 868. Compute gamma. (d) Suppose that Bob issues the challenge r = 501. Compute Alice's response y. (e) Perform Bob's calculations to verify y." -Douglas R. Stinson- See "Cryptography: Theory and Practice" by Douglas R. Stinson pages 303-304. */ #include #include "lip.h" int main(void) { long alpha = 11538, p = 122503, q = 1201; long a = 357, k = 868, r = 501; verylong za = 0, zb = 0, zc = 0, zk = 0, zp = 0; verylong zq = 0, zr = 0, zv = 0, zy = 0; verylong zalpha = 0, zgamma = 0; zintoz(alpha, &zalpha); zintoz(a, &za); zintoz(k, &zk); zintoz(p, &zp); zintoz(q, &zq); zintoz(r, &zr); zexpmod(zalpha, zq, zp, &zb); printf("alpha = %ld\n", alpha); printf("p = %ld\n", p); printf("q = %ld\n", q); printf("a = %ld\n", a); printf("k = %ld\n", k); printf("r = %ld\n", r); printf("alpha ^ q mod p = "); zwriteln(zb); zcopy(za, &zb); znegate(&zb); zadd(zb, zq, &zc); zexpmod(zalpha, zc, zp, &zv); printf("v = "); zwriteln(zv); zexpmod(zalpha, zk, zp, &zgamma); printf("gamma = "); zwriteln(zgamma); zmulmod(za, zr, zq, &zb); zaddmod(zk, zb, zq, &zy); printf("y = "); zwriteln(zy); zexpmod(zalpha, zy, zp, &zb); zexpmod(zv, zr, zp, &zc); zmulmod(zb, zc, zp, &za); if (zcompare(za, zgamma) == 0) printf("y verified\n"); else printf("y not verfied\n"); zfree(&za); zfree(&zb); zfree(&zc); zfree(&zk); zfree(&zp); zfree(&zq); zfree(&zr); zfree(&zy); zfree(&zalpha); zfree(&zgamma); return 0; }