您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

92 行
3.1 KiB

  1. /* Copyright (c) 2015, Google Inc.
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  14. #ifndef OPENSSL_HEADER_CMAC_H
  15. #define OPENSSL_HEADER_CMAC_H
  16. #include <openssl/base.h>
  17. #if defined(__cplusplus)
  18. extern "C" {
  19. #endif
  20. // CMAC.
  21. //
  22. // CMAC is a MAC based on AES-CBC and defined in
  23. // https://tools.ietf.org/html/rfc4493#section-2.3.
  24. // One-shot functions.
  25. // AES_CMAC calculates the 16-byte, CMAC authenticator of |in_len| bytes of
  26. // |in| and writes it to |out|. The |key_len| may be 16 or 32 bytes to select
  27. // between AES-128 and AES-256. It returns one on success or zero on error.
  28. OPENSSL_EXPORT int AES_CMAC(uint8_t out[16], const uint8_t *key, size_t key_len,
  29. const uint8_t *in, size_t in_len);
  30. // Incremental interface.
  31. // CMAC_CTX_new allocates a fresh |CMAC_CTX| and returns it, or NULL on
  32. // error.
  33. OPENSSL_EXPORT CMAC_CTX *CMAC_CTX_new(void);
  34. // CMAC_CTX_free frees a |CMAC_CTX|.
  35. OPENSSL_EXPORT void CMAC_CTX_free(CMAC_CTX *ctx);
  36. // CMAC_CTX_copy sets |out| to be a duplicate of the current state |in|. It
  37. // returns one on success and zero on error.
  38. OPENSSL_EXPORT int CMAC_CTX_copy(CMAC_CTX *out, const CMAC_CTX *in);
  39. // CMAC_Init configures |ctx| to use the given |key| and |cipher|. The CMAC RFC
  40. // only specifies the use of AES-128 thus |key_len| should be 16 and |cipher|
  41. // should be |EVP_aes_128_cbc()|. However, this implementation also supports
  42. // AES-256 by setting |key_len| to 32 and |cipher| to |EVP_aes_256_cbc()|. The
  43. // |engine| argument is ignored.
  44. //
  45. // It returns one on success or zero on error.
  46. OPENSSL_EXPORT int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t key_len,
  47. const EVP_CIPHER *cipher, ENGINE *engine);
  48. // CMAC_Reset resets |ctx| so that a fresh message can be authenticated.
  49. OPENSSL_EXPORT int CMAC_Reset(CMAC_CTX *ctx);
  50. // CMAC_Update processes |in_len| bytes of message from |in|. It returns one on
  51. // success or zero on error.
  52. OPENSSL_EXPORT int CMAC_Update(CMAC_CTX *ctx, const uint8_t *in, size_t in_len);
  53. // CMAC_Final sets |*out_len| to 16 and, if |out| is not NULL, writes 16 bytes
  54. // of authenticator to it. It returns one on success or zero on error.
  55. OPENSSL_EXPORT int CMAC_Final(CMAC_CTX *ctx, uint8_t *out, size_t *out_len);
  56. #if defined(__cplusplus)
  57. } // extern C
  58. extern "C++" {
  59. BSSL_NAMESPACE_BEGIN
  60. BORINGSSL_MAKE_DELETER(CMAC_CTX, CMAC_CTX_free)
  61. BSSL_NAMESPACE_END
  62. } // extern C++
  63. #endif
  64. #endif // OPENSSL_HEADER_CMAC_H