securitypolicy_mbedtls_common.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  3. *
  4. * Copyright 2019 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
  5. */
  6. #ifndef UA_SECURITYPOLICY_MBEDTLS_COMMON_H_
  7. #define UA_SECURITYPOLICY_MBEDTLS_COMMON_H_
  8. #include <open62541/plugin/securitypolicy.h>
  9. #ifdef UA_ENABLE_ENCRYPTION
  10. #include <mbedtls/md.h>
  11. #include <mbedtls/x509_crt.h>
  12. #include <mbedtls/ctr_drbg.h>
  13. #if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
  14. #define MBEDTLS_ENTROPY_POLL_METHOD mbedtls_platform_entropy_poll
  15. #else
  16. // MBEDTLS_ENTROPY_HARDWARE_ALT should be defined if your hardware does not supportd platform entropy
  17. #define MBEDTLS_ENTROPY_POLL_METHOD mbedtls_hardware_poll
  18. #endif
  19. #define UA_SHA1_LENGTH 20
  20. _UA_BEGIN_DECLS
  21. void
  22. swapBuffers(UA_ByteString *const bufA, UA_ByteString *const bufB);
  23. void
  24. mbedtls_hmac(mbedtls_md_context_t *context, const UA_ByteString *key,
  25. const UA_ByteString *in, unsigned char *out);
  26. UA_StatusCode
  27. mbedtls_generateKey(mbedtls_md_context_t *context,
  28. const UA_ByteString *secret, const UA_ByteString *seed,
  29. UA_ByteString *out);
  30. UA_StatusCode
  31. mbedtls_verifySig_sha1(mbedtls_x509_crt *certificate, const UA_ByteString *message,
  32. const UA_ByteString *signature);
  33. UA_StatusCode
  34. mbedtls_sign_sha1(mbedtls_pk_context *localPrivateKey,
  35. mbedtls_ctr_drbg_context *drbgContext,
  36. const UA_ByteString *message,
  37. UA_ByteString *signature);
  38. UA_StatusCode
  39. mbedtls_thumbprint_sha1(const UA_ByteString *certificate,
  40. UA_ByteString *thumbprint);
  41. /* Set the hashing scheme before calling
  42. * E.g. mbedtls_rsa_set_padding(context, MBEDTLS_RSA_PKCS_V21, MBEDTLS_MD_SHA1); */
  43. UA_StatusCode
  44. mbedtls_encrypt_rsaOaep(mbedtls_rsa_context *context,
  45. mbedtls_ctr_drbg_context *drbgContext,
  46. UA_ByteString *data, const size_t plainTextBlockSize);
  47. UA_StatusCode
  48. mbedtls_decrypt_rsaOaep(mbedtls_pk_context *localPrivateKey,
  49. mbedtls_ctr_drbg_context *drbgContext,
  50. UA_ByteString *data);
  51. _UA_END_DECLS
  52. #endif
  53. #endif /* UA_SECURITYPOLICY_MBEDTLS_COMMON_H_ */