ctc_asn_public.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* ctc_asn_public.h
  2. *
  3. * Copyright (C) 2006-2011 Sawtooth Consulting Ltd.
  4. *
  5. * This file is part of CyaSSL.
  6. *
  7. * CyaSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * CyaSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  20. */
  21. #ifndef CTAO_CRYPT_ASN_PUBLIC_H
  22. #define CTAO_CRYPT_ASN_PUBLIC_H
  23. #include "ctc_types.h"
  24. #ifdef CYASSL_CERT_GEN
  25. #include "ctc_rsa.h"
  26. #endif
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* Certificate file Type */
  31. enum CertType {
  32. CERT_TYPE = 0,
  33. PRIVATEKEY_TYPE,
  34. CA_TYPE
  35. };
  36. #ifdef CYASSL_CERT_GEN
  37. enum Ctc_Misc {
  38. CTC_NAME_SIZE = 64,
  39. CTC_SERIAL_SIZE = 8
  40. };
  41. typedef struct CertName {
  42. char country[CTC_NAME_SIZE];
  43. char state[CTC_NAME_SIZE];
  44. char locality[CTC_NAME_SIZE];
  45. char sur[CTC_NAME_SIZE];
  46. char org[CTC_NAME_SIZE];
  47. char unit[CTC_NAME_SIZE];
  48. char commonName[CTC_NAME_SIZE];
  49. char email[CTC_NAME_SIZE]; /* !!!! email has to be last !!!! */
  50. } CertName;
  51. /* for user to fill for certificate generation */
  52. typedef struct Cert {
  53. int version; /* x509 version */
  54. byte serial[CTC_SERIAL_SIZE]; /* serial number */
  55. int sigType; /* signature algo type */
  56. CertName issuer; /* issuer info */
  57. int daysValid; /* validity days */
  58. int selfSigned; /* self signed flag */
  59. CertName subject; /* subject info */
  60. /* internal use only */
  61. int bodySz; /* pre sign total size */
  62. int keyType; /* public key type of subject */
  63. } Cert;
  64. /* Initialize and Set Certficate defaults:
  65. version = 3 (0x2)
  66. serial = 0 (Will be randomly generated)
  67. sigType = MD5_WITH_RSA
  68. issuer = blank
  69. daysValid = 500
  70. selfSigned = 1 (true) use subject as issuer
  71. subject = blank
  72. keyType = RSA_KEY (default)
  73. */
  74. CYASSL_API void InitCert(Cert*);
  75. CYASSL_API int MakeCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*, RNG*);
  76. CYASSL_API int SignCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*, RNG*);
  77. CYASSL_API int MakeSelfCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*,
  78. RNG*);
  79. CYASSL_API int SetIssuer(Cert*, const char*);
  80. #ifdef HAVE_NTRU
  81. CYASSL_API int MakeNtruCert(Cert*, byte* derBuffer, word32 derSz,
  82. const byte* ntruKey, word16 keySz, RNG*);
  83. #endif
  84. #endif /* CYASSL_CERT_GEN */
  85. #if defined(CYASSL_KEY_GEN) || defined(CYASSL_CERT_GEN)
  86. CYASSL_API int DerToPem(const byte* der, word32 derSz, byte* output,
  87. word32 outputSz, int type);
  88. #endif
  89. #ifdef __cplusplus
  90. } /* extern "C" */
  91. #endif
  92. #endif /* CTAO_CRYPT_ASN_PUBLIC_H */