You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

211 lines
7.9 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. smdevp.h
  3. gSOAP interface for (signed) message digest
  4. gSOAP XML Web services tools
  5. Copyright (C) 2000-2010, Robert van Engelen, Genivia Inc., All Rights Reserved.
  6. This part of the software is released under one of the following licenses:
  7. GPL, the gSOAP public license, or Genivia's license for commercial use.
  8. --------------------------------------------------------------------------------
  9. gSOAP public license.
  10. The contents of this file are subject to the gSOAP Public License Version 1.3
  11. (the "License"); you may not use this file except in compliance with the
  12. License. You may obtain a copy of the License at
  13. http://www.cs.fsu.edu/~engelen/soaplicense.html
  14. Software distributed under the License is distributed on an "AS IS" basis,
  15. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  16. for the specific language governing rights and limitations under the License.
  17. The Initial Developer of the Original Code is Robert A. van Engelen.
  18. Copyright (C) 2000-2010, Robert van Engelen, Genivia, Inc., All Rights Reserved.
  19. --------------------------------------------------------------------------------
  20. GPL license.
  21. This program is free software; you can redistribute it and/or modify it under
  22. the terms of the GNU General Public License as published by the Free Software
  23. Foundation; either version 2 of the License, or (at your option) any later
  24. version.
  25. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  26. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  27. PARTICULAR PURPOSE. See the GNU General Public License for more details.
  28. You should have received a copy of the GNU General Public License along with
  29. this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  30. Place, Suite 330, Boston, MA 02111-1307 USA
  31. Author contact information:
  32. engelen@genivia.com / engelen@acm.org
  33. This program is released under the GPL with the additional exemption that
  34. compiling, linking, and/or using OpenSSL is allowed.
  35. --------------------------------------------------------------------------------
  36. A commercial use license is available from Genivia, Inc., contact@genivia.com
  37. --------------------------------------------------------------------------------
  38. */
  39. #ifndef SMDEVP_H
  40. #define SMDEVP_H
  41. #include "stdsoap2.h"
  42. #ifdef WITH_OPENSSL
  43. #include <openssl/evp.h>
  44. #include <openssl/hmac.h>
  45. #endif
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #endif
  49. /** Expose EVP_PKEY in a portable representation */
  50. #define SOAP_SMD_KEY_TYPE EVP_PKEY
  51. /** Expose EVP_MAX_MD_SIZE in a portable representation */
  52. #define SOAP_SMD_MAX_SIZE EVP_MAX_MD_SIZE
  53. /** MD5 digest size in octets */
  54. #define SOAP_SMD_MD5_SIZE (16)
  55. /** SHA1 digest size in octets */
  56. #define SOAP_SMD_SHA1_SIZE (20)
  57. /** SHA256 digest size in octets */
  58. #define SOAP_SMD_SHA256_SIZE (32)
  59. /** SHA512 digest size in octets */
  60. #define SOAP_SMD_SHA512_SIZE (64)
  61. /******************************************************************************\
  62. *
  63. * Supported algorithms
  64. *
  65. \******************************************************************************/
  66. #define SOAP_SMD_NONE (0x0000)
  67. #define SOAP_SMD_HASH (0x0003)
  68. #define SOAP_SMD_ALGO (0x000C)
  69. #define SOAP_SMD_MASK (0x01FF)
  70. /** MD5 hash */
  71. #define SOAP_SMD_MD5 (0x00)
  72. /** SHA1 hash */
  73. #define SOAP_SMD_SHA1 (0x01)
  74. /** SHA256 hash */
  75. #define SOAP_SMD_SHA256 (0x02)
  76. /** SHA512 hash */
  77. #define SOAP_SMD_SHA512 (0x03)
  78. /** HMAC */
  79. #define SOAP_SMD_HMAC (0x00)
  80. /** Digest */
  81. #define SOAP_SMD_DGST (0x04)
  82. /** Sign */
  83. #define SOAP_SMD_SIGN (0x08)
  84. /** Verify */
  85. #define SOAP_SMD_VRFY (0x0C)
  86. /** DSA (RSA) signature */
  87. #define SOAP_SMD_DSA (0x10)
  88. /** HMAC-MD5 shared key signature algorithm */
  89. #define SOAP_SMD_HMAC_MD5 (SOAP_SMD_HMAC | SOAP_SMD_MD5)
  90. /** HMAC-SHA1 shared key signature algorithm */
  91. #define SOAP_SMD_HMAC_SHA1 (SOAP_SMD_HMAC | SOAP_SMD_SHA1)
  92. /** HMAC-SHA256 shared key signature algorithm */
  93. #define SOAP_SMD_HMAC_SHA256 (SOAP_SMD_HMAC | SOAP_SMD_SHA256)
  94. /** HMAC-SHA512 shared key signature algorithm */
  95. #define SOAP_SMD_HMAC_SHA512 (SOAP_SMD_HMAC | SOAP_SMD_SHA512)
  96. /** DGST-MD5 digest algorithm */
  97. #define SOAP_SMD_DGST_MD5 (SOAP_SMD_DGST | SOAP_SMD_MD5)
  98. /** DGST-SHA1 digest algorithm */
  99. #define SOAP_SMD_DGST_SHA1 (SOAP_SMD_DGST | SOAP_SMD_SHA1)
  100. /** DGST-SHA256 digest algorithm */
  101. #define SOAP_SMD_DGST_SHA256 (SOAP_SMD_DGST | SOAP_SMD_SHA256)
  102. /** DGST-SHA512 digest algorithm */
  103. #define SOAP_SMD_DGST_SHA512 (SOAP_SMD_DGST | SOAP_SMD_SHA512)
  104. /** DSA-MD5 digest algorithm */
  105. #define SOAP_SMD_DGST_MD5 (SOAP_SMD_DGST | SOAP_SMD_MD5)
  106. /** DGST-SHA1 digest algorithm */
  107. #define SOAP_SMD_DGST_SHA1 (SOAP_SMD_DGST | SOAP_SMD_SHA1)
  108. /** DGST-SHA256 digest algorithm */
  109. #define SOAP_SMD_DGST_SHA256 (SOAP_SMD_DGST | SOAP_SMD_SHA256)
  110. /** DGST-SHA512 digest algorithm */
  111. #define SOAP_SMD_DGST_SHA512 (SOAP_SMD_DGST | SOAP_SMD_SHA512)
  112. /** RSA-MD5 secret key signature algorithm */
  113. #define SOAP_SMD_SIGN_RSA_MD5 (SOAP_SMD_SIGN | SOAP_SMD_MD5)
  114. /** RSA-SHA1 secret key signature algorithm */
  115. #define SOAP_SMD_SIGN_RSA_SHA1 (SOAP_SMD_SIGN | SOAP_SMD_SHA1)
  116. /** RSA-SHA256 secret key signature algorithm */
  117. #define SOAP_SMD_SIGN_RSA_SHA256 (SOAP_SMD_SIGN | SOAP_SMD_SHA256)
  118. /** RSA-SHA512 secret key signature algorithm */
  119. #define SOAP_SMD_SIGN_RSA_SHA512 (SOAP_SMD_SIGN | SOAP_SMD_SHA512)
  120. /** DSA-MD5 secret key signature algorithm */
  121. #define SOAP_SMD_SIGN_DSA_MD5 (SOAP_SMD_SIGN | SOAP_SMD_DSA | SOAP_SMD_MD5)
  122. /** DSA-SHA1 secret key signature algorithm */
  123. #define SOAP_SMD_SIGN_DSA_SHA1 (SOAP_SMD_SIGN | SOAP_SMD_DSA | SOAP_SMD_SHA1)
  124. /** DSA-SHA256 secret key signature algorithm */
  125. #define SOAP_SMD_SIGN_DSA_SHA256 (SOAP_SMD_SIGN | SOAP_SMD_DSA | SOAP_SMD_SHA256)
  126. /** DSA-SHA512 secret key signature algorithm */
  127. #define SOAP_SMD_SIGN_DSA_SHA512 (SOAP_SMD_SIGN | SOAP_SMD_DSA | SOAP_SMD_SHA512)
  128. /** RSA-MD5 secret key signature verification algorithm */
  129. #define SOAP_SMD_VRFY_RSA_MD5 (SOAP_SMD_VRFY | SOAP_SMD_MD5)
  130. /** RSA-SHA1 secret key signature verification algorithm */
  131. #define SOAP_SMD_VRFY_RSA_SHA1 (SOAP_SMD_VRFY | SOAP_SMD_SHA1)
  132. /** RSA-SHA256 secret key signature verification algorithm */
  133. #define SOAP_SMD_VRFY_RSA_SHA256 (SOAP_SMD_VRFY | SOAP_SMD_SHA256)
  134. /** RSA-SHA512 secret key signature verification algorithm */
  135. #define SOAP_SMD_VRFY_RSA_SHA512 (SOAP_SMD_VRFY | SOAP_SMD_SHA512)
  136. /** DSA-MD5 secret key signature verification algorithm */
  137. #define SOAP_SMD_VRFY_DSA_MD5 (SOAP_SMD_VRFY | SOAP_SMD_DSA | SOAP_SMD_MD5)
  138. /** DSA-SHA1 secret key signature verification algorithm */
  139. #define SOAP_SMD_VRFY_DSA_SHA1 (SOAP_SMD_VRFY | SOAP_SMD_DSA | SOAP_SMD_SHA1)
  140. /** DSA-SHA256 secret key signature verification algorithm */
  141. #define SOAP_SMD_VRFY_DSA_SHA256 (SOAP_SMD_VRFY | SOAP_SMD_DSA | SOAP_SMD_SHA256)
  142. /** DSA-SHA512 secret key signature verification algorithm */
  143. #define SOAP_SMD_VRFY_DSA_SHA512 (SOAP_SMD_VRFY | SOAP_SMD_DSA | SOAP_SMD_SHA512)
  144. /** Additional flag: msg sends will pass through digest/signature algorithm */
  145. #define SOAP_SMD_PASSTHRU (0x100)
  146. /**
  147. @struct soap_smd_data
  148. @brief The smdevp engine context data, which is hooked up to soap->data[0]
  149. */
  150. struct soap_smd_data
  151. { int alg; /**< The digest or signature algorithm used */
  152. void *ctx; /**< EVP_MD_CTX or HMAC_CTX */
  153. const void *key; /**< EVP_PKEY */
  154. int (*fsend)(struct soap*, const char*, size_t);
  155. size_t (*frecv)(struct soap*, char*, size_t);
  156. soap_mode mode; /**< to preserve soap->mode value */
  157. };
  158. /******************************************************************************\
  159. *
  160. * soap_smd API functions
  161. *
  162. \******************************************************************************/
  163. size_t soap_smd_size(int alg, const void *key);
  164. int soap_smd_begin(struct soap *soap, int alg, const void *key, int keylen);
  165. int soap_smd_end(struct soap *soap, char *buf, int *len);
  166. int soap_smd_init(struct soap *soap, struct soap_smd_data *data, int alg, const void *key, int keylen);
  167. int soap_smd_update(struct soap *soap, struct soap_smd_data *data, const char *buf, size_t len);
  168. int soap_smd_final(struct soap *soap, struct soap_smd_data *data, char *buf, int *len);
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. #endif