rsa.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. /* rsa.h
  4. *
  5. * Copyright (C) 2006-2014 wolfSSL Inc.
  6. *
  7. * This file is part of CyaSSL.
  8. *
  9. * CyaSSL is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * CyaSSL is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #ifndef CTAO_CRYPT_RSA_H
  24. #define CTAO_CRYPT_RSA_H
  25. #include <stdint.h>
  26. #ifndef word32
  27. typedef uint32_t word32;
  28. #endif
  29. #ifndef byte
  30. typedef uint8_t byte;
  31. #endif
  32. #include "integer.h"
  33. enum {
  34. RSA_PUBLIC = 0,
  35. RSA_PRIVATE = 1
  36. };
  37. /* RSA */
  38. typedef struct RSAKey {
  39. mp_int n, e, d, p, q, dP, dQ, u;
  40. int type; /* public or private */
  41. } RSAKey;
  42. int InitRSAKey(RSAKey *key);
  43. int FreeRSAKey(RSAKey *key);
  44. int RSAPublicEncrypt(const byte *in, word32 inLen, byte *out,
  45. word32 outLen, RSAKey *key);
  46. int RSAPrivateDecryptInline(byte *in, word32 inLen, byte* *out,
  47. RSAKey *key);
  48. int RSAPrivateDecrypt(const byte *in, word32 inLen, byte *out,
  49. word32 outLen, RSAKey *key);
  50. int RSASSL_Sign(const byte *in, word32 inLen, byte *out,
  51. word32 outLen, RSAKey *key);
  52. int RSASSL_VerifyInline(byte *in, word32 inLen, byte* *out,
  53. RSAKey *key);
  54. int RSASSL_Verify(const byte *in, word32 inLen, byte *out,
  55. word32 outLen, RSAKey *key);
  56. int RSAEncryptSize(RSAKey *key);
  57. int RSAPrivateKeyDecode(const byte *input, word32 *inOutIdx,
  58. RSAKey *key, word32 inSz);
  59. int RSAPublicKeyDecode(const byte *input, word32 *inOutIdx,
  60. RSAKey *key, word32 inSz);
  61. int RSAPublicKeyDecodeRaw(const byte *n, word32 nSz, const byte *e,
  62. word32 eSz, RSAKey *key);
  63. int RSAFlattenPublicKey(RSAKey *key, byte *e, word32 *eSz, byte *n,
  64. word32 *nSz);
  65. int MakeRSAKey(RSAKey *key, int size, long e);
  66. int RSAKeyToDer(RSAKey*, byte *output, word32 inLen);
  67. #endif /* CTAO_CRYPT_RSA_H */