hmac.h 989 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the License); you may
  5. * not use this file except in compliance with the License.
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. */
  9. #ifndef GMSSL_HMAC_H
  10. #define GMSSL_HMAC_H
  11. #include <string.h>
  12. #include <gmssl/digest.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #define HMAC_MAX_SIZE (DIGEST_MAX_SIZE)
  17. typedef struct hmac_ctx_st {
  18. const DIGEST *digest;
  19. DIGEST_CTX digest_ctx;
  20. DIGEST_CTX i_ctx;
  21. DIGEST_CTX o_ctx;
  22. } HMAC_CTX;
  23. size_t hmac_size(const HMAC_CTX *ctx);
  24. int hmac_init(HMAC_CTX *ctx, const DIGEST *digest, const uint8_t *key, size_t keylen);
  25. int hmac_update(HMAC_CTX *ctx, const uint8_t *data, size_t datalen);
  26. int hmac_finish(HMAC_CTX *ctx, uint8_t *mac, size_t *maclen);
  27. int hmac(const DIGEST *md, const uint8_t *key, size_t keylen,
  28. const uint8_t *data, size_t dlen,
  29. uint8_t *mac, size_t *maclen);
  30. #ifdef __cplusplus
  31. }
  32. #endif
  33. #endif