rsaalloc.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. RSApub*
  13. rsapuballoc(void)
  14. {
  15. RSApub *rsa;
  16. rsa = mallocz(sizeof(*rsa), 1);
  17. if(rsa == nil)
  18. sysfatal("rsapuballoc");
  19. return rsa;
  20. }
  21. void
  22. rsapubfree(RSApub *rsa)
  23. {
  24. if(rsa == nil)
  25. return;
  26. mpfree(rsa->ek);
  27. mpfree(rsa->n);
  28. free(rsa);
  29. }
  30. RSApriv*
  31. rsaprivalloc(void)
  32. {
  33. RSApriv *rsa;
  34. rsa = mallocz(sizeof(*rsa), 1);
  35. if(rsa == nil)
  36. sysfatal("rsaprivalloc");
  37. return rsa;
  38. }
  39. void
  40. rsaprivfree(RSApriv *rsa)
  41. {
  42. if(rsa == nil)
  43. return;
  44. mpfree(rsa->pub.ek);
  45. mpfree(rsa->pub.n);
  46. mpfree(rsa->dk);
  47. mpfree(rsa->p);
  48. mpfree(rsa->q);
  49. mpfree(rsa->kp);
  50. mpfree(rsa->kq);
  51. mpfree(rsa->c2);
  52. free(rsa);
  53. }