egverify.c 931 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "os.h"
  10. #include <mp.h>
  11. #include <libsec.h>
  12. int
  13. egverify(EGpub *pub, EGsig *sig, mpint *m)
  14. {
  15. mpint *p = pub->p, *alpha = pub->alpha;
  16. mpint *r = sig->r, *s = sig->s;
  17. mpint *v1, *v2, *rs;
  18. int rv = -1;
  19. if(mpcmp(r, mpone) < 0 || mpcmp(r, p) >= 0)
  20. return rv;
  21. v1 = mpnew(0);
  22. rs = mpnew(0);
  23. v2 = mpnew(0);
  24. mpexp(pub->key, r, p, v1);
  25. mpexp(r, s, p, rs);
  26. mpmul(v1, rs, v1);
  27. mpmod(v1, p, v1);
  28. mpexp(alpha, m, p, v2);
  29. if(mpcmp(v1, v2) == 0)
  30. rv = 0;
  31. mpfree(v1);
  32. mpfree(rs);
  33. mpfree(v2);
  34. return rv;
  35. }