cipher.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. *
  3. * Embedded Linux library
  4. *
  5. * Copyright (C) 2015 Intel Corporation. All rights reserved.
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. */
  22. #ifndef __ELL_CIPHER_H
  23. #define __ELL_CIPHER_H
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. struct l_cipher;
  28. enum l_cipher_type {
  29. L_CIPHER_AES = 0,
  30. L_CIPHER_AES_CBC,
  31. L_CIPHER_AES_CTR,
  32. L_CIPHER_ARC4,
  33. L_CIPHER_DES,
  34. L_CIPHER_DES_CBC,
  35. L_CIPHER_DES3_EDE_CBC,
  36. L_CIPHER_RC2_CBC,
  37. };
  38. struct l_cipher *l_cipher_new(enum l_cipher_type type,
  39. const void *key, size_t key_length);
  40. void l_cipher_free(struct l_cipher *cipher);
  41. bool l_cipher_encrypt(struct l_cipher *cipher,
  42. const void *in, void *out, size_t len);
  43. bool l_cipher_encryptv(struct l_cipher *cipher,
  44. const struct iovec *in, size_t in_cnt,
  45. const struct iovec *out, size_t out_cnt);
  46. bool l_cipher_decrypt(struct l_cipher *cipher,
  47. const void *in, void *out, size_t len);
  48. bool l_cipher_decryptv(struct l_cipher *cipher,
  49. const struct iovec *in, size_t in_cnt,
  50. const struct iovec *out, size_t out_cnt);
  51. bool l_cipher_set_iv(struct l_cipher *cipher, const uint8_t *iv,
  52. size_t iv_length);
  53. struct l_aead_cipher;
  54. enum l_aead_cipher_type {
  55. L_AEAD_CIPHER_AES_CCM = 0,
  56. L_AEAD_CIPHER_AES_GCM,
  57. };
  58. struct l_aead_cipher *l_aead_cipher_new(enum l_aead_cipher_type type,
  59. const void *key, size_t key_length,
  60. size_t tag_length);
  61. void l_aead_cipher_free(struct l_aead_cipher *cipher);
  62. bool l_aead_cipher_encrypt(struct l_aead_cipher *cipher,
  63. const void *in, size_t in_len,
  64. const void *ad, size_t ad_len,
  65. const void *nonce, size_t nonce_len,
  66. void *out, size_t out_len);
  67. bool l_aead_cipher_decrypt(struct l_aead_cipher *cipher,
  68. const void *in, size_t in_len,
  69. const void *ad, size_t ad_len,
  70. const void *nonce, size_t nonce_len,
  71. void *out, size_t out_len);
  72. bool l_cipher_is_supported(enum l_cipher_type type);
  73. bool l_aead_cipher_is_supported(enum l_aead_cipher_type type);
  74. #ifdef __cplusplus
  75. }
  76. #endif
  77. #endif /* __ELL_CIPHER_H */