crypto_cipher.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Copyright (c) 2001, Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2019, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file crypto_cipher.h
  8. *
  9. * \brief Headers for crypto_cipher.c
  10. **/
  11. #ifndef TOR_CRYPTO_CIPHER_H
  12. #define TOR_CRYPTO_CIPHER_H
  13. #include "orconfig.h"
  14. #include <stdio.h>
  15. #include "lib/cc/torint.h"
  16. /** Length of our symmetric cipher's keys of 128-bit. */
  17. #define CIPHER_KEY_LEN 16
  18. /** Length of our symmetric cipher's IV of 128-bit. */
  19. #define CIPHER_IV_LEN 16
  20. /** Length of our symmetric cipher's keys of 256-bit. */
  21. #define CIPHER256_KEY_LEN 32
  22. typedef struct aes_cnt_cipher crypto_cipher_t;
  23. /* environment setup */
  24. crypto_cipher_t *crypto_cipher_new(const char *key);
  25. crypto_cipher_t *crypto_cipher_new_with_bits(const char *key, int bits);
  26. crypto_cipher_t *crypto_cipher_new_with_iv(const char *key, const char *iv);
  27. crypto_cipher_t *crypto_cipher_new_with_iv_and_bits(const uint8_t *key,
  28. const uint8_t *iv,
  29. int bits);
  30. void crypto_cipher_free_(crypto_cipher_t *env);
  31. #define crypto_cipher_free(c) \
  32. FREE_AND_NULL(crypto_cipher_t, crypto_cipher_free_, (c))
  33. /* symmetric crypto */
  34. const char *crypto_cipher_get_key(crypto_cipher_t *env);
  35. int crypto_cipher_encrypt(crypto_cipher_t *env, char *to,
  36. const char *from, size_t fromlen);
  37. int crypto_cipher_decrypt(crypto_cipher_t *env, char *to,
  38. const char *from, size_t fromlen);
  39. void crypto_cipher_crypt_inplace(crypto_cipher_t *env, char *d, size_t len);
  40. int crypto_cipher_encrypt_with_iv(const char *key,
  41. char *to, size_t tolen,
  42. const char *from, size_t fromlen);
  43. int crypto_cipher_decrypt_with_iv(const char *key,
  44. char *to, size_t tolen,
  45. const char *from, size_t fromlen);
  46. #endif /* !defined(TOR_CRYPTO_CIPHER_H) */