egtest.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. void
  13. main(void)
  14. {
  15. EGpriv *sk;
  16. mpint *m, *gamma, *delta, *in, *out;
  17. int plen, shift;
  18. fmtinstall('B', mpconv);
  19. sk = egprivalloc();
  20. sk->pub.p = uitomp(2357, nil);
  21. sk->pub.alpha = uitomp(2, nil);
  22. sk->pub.key = uitomp(1185, nil);
  23. sk->secret = uitomp(1751, nil);
  24. m = uitomp(2035, nil);
  25. plen = mpsignif(sk->pub.p)+1;
  26. shift = ((plen+Dbits-1)/Dbits)*Dbits;
  27. gamma = uitomp(1430, nil);
  28. delta = uitomp(697, nil);
  29. out = mpnew(0);
  30. in = mpnew(0);
  31. mpleft(gamma, shift, in);
  32. mpadd(delta, in, in);
  33. egdecrypt(sk, in, out);
  34. if(mpcmp(m, out) != 0)
  35. print("decrypt failed to recover message\n");
  36. }