wm_crypto.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * @file wm_crypto.h
  3. *
  4. * @brief crypto driver module
  5. *
  6. * @author dave
  7. *
  8. * Copyright (c) 2014 Winner Microelectronics Co., Ltd.
  9. */
  10. #ifndef WM_CRYPTO_H
  11. #define WM_CRYPTO_H
  12. /**
  13. * @brief Encrypt plain data by 128 AES crypto
  14. * @param[in] key the key for encryption
  15. * @param[in] iv the IV value for encryption
  16. * @param[in] data where the plain data stored
  17. * @param[in] data_len length of the plain data to be encrypted
  18. * @retval 0 finish Encryption successfully
  19. * @retval -1 Error
  20. * @note Encrypted data will be placed into the plain @data area
  21. *
  22. */
  23. int aes_128_cbc_encrypt (const u8 *key, const u8 *iv, u8 *data, size_t data_len) ;
  24. /**
  25. * @brief Decrypt data by 128 AES crypto
  26. * @param[in] key the key for encryption
  27. * @param[in] iv the IV value for encryption
  28. * @param[in] data where the plain data stored
  29. * @param[in] data_len length of the plain data to be decrypted
  30. * @retval 0 finish Decryption successfully
  31. * @retval -1 Error
  32. * @note plain data will be placed into the encrypted @data area
  33. *
  34. */
  35. int aes_128_cbc_decrypt(const u8 *key, const u8 *iv, u8 *data,
  36. size_t data_len);
  37. /**
  38. * @brief XOR RC4 stream to given data with skip-stream-start
  39. * @param[in] key RC4 key
  40. * @param[in] keylen RC4 key length
  41. * @param[in] data data to be XOR'ed with RC4 stream
  42. * @param[in] data_len length of the plain data to be encrypted
  43. * @retval 0 finish Encryption/Decryption successfully
  44. * @retval -1 Error
  45. * @note this function should be used for Encryption & Decryption both For the Encryption, the plain @data
  46. * will be replaced by the encrypted output, and vice versa;
  47. */
  48. int rc4(const u8 *key, size_t keylen, u8 *data, size_t data_len);
  49. /**
  50. * @brief MD5 hash for data vector
  51. * @param[in] addr Pointers to the data area
  52. * @param[in] len Lengths of the data block
  53. * @param[in] mac Buffer for the hash (16 bytes)
  54. * @retval 0 finish caculation successfully
  55. * @retval -1 Error
  56. * @note
  57. */
  58. int md5(const u8 *addr, int len, u8 *mac);
  59. /**
  60. * @brief HMAC-MD5 over data buffer (RFC 2104)
  61. * @param[in] key Key for HMAC operations
  62. * @param[in] keylen Length of the key in bytes
  63. * @param[in] data data to be caculated
  64. * @param[in] data_len Lengths of the data block
  65. * @param[in] mac Buffer for the hash (16 bytes)
  66. * @retval 0 finish caculation successfully
  67. * @retval -1 Error
  68. * @note
  69. */
  70. int hmac_md5(const u8 *key, size_t key_len, const u8 *data, size_t data_len, u8 *mac);
  71. /**
  72. * @brief SHA1 hash for data vector
  73. * @param[in] addr Pointers to the data area
  74. * @param[in] len Lengths of the data block
  75. * @param[in] mac Buffer for the hash (16 bytes)
  76. * @retval 0 finish caculation successfully
  77. * @retval -1 Error
  78. * @note
  79. */
  80. int sha1(const u8 *addr, int len, u8 *mac);
  81. #endif