ua_securitypolicy_common.c 1.0 KB

123456789101112131415161718192021222324252627282930
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. */
  5. #include <mbedtls/sha1.h>
  6. #include <mbedtls/version.h>
  7. #include "ua_securitypolicy_common.h"
  8. void
  9. sha1(const unsigned char *input, size_t ilen, unsigned char output[20]) {
  10. mbedtls_sha1_context sha1Context;
  11. mbedtls_sha1_init(&sha1Context);
  12. #if MBEDTLS_VERSION_NUMBER >= 0x02070000
  13. // TODO check return status / actually only/always return 0
  14. mbedtls_sha1_starts_ret(&sha1Context);
  15. // TODO check return status / actually only/always return 0
  16. mbedtls_sha1_update_ret(&sha1Context, input, ilen);
  17. // TODO check return status / actually only/always return 0
  18. mbedtls_sha1_finish_ret(&sha1Context, output);
  19. #else
  20. mbedtls_sha1_starts(&sha1Context);
  21. mbedtls_sha1_update(&sha1Context, input, ilen);
  22. mbedtls_sha1_finish(&sha1Context, output);
  23. #endif
  24. mbedtls_sha1_free(&sha1Context);
  25. }