crypto.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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-2018, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file crypto.h
  8. *
  9. * \brief Headers for crypto.c
  10. **/
  11. #ifndef TOR_CRYPTO_H
  12. #define TOR_CRYPTO_H
  13. #include "orconfig.h"
  14. #include <stdio.h>
  15. #include "lib/cc/torint.h"
  16. #include "lib/crypt_ops/crypto_rsa.h"
  17. /** Length of our symmetric cipher's keys of 128-bit. */
  18. #define CIPHER_KEY_LEN 16
  19. /** Length of our symmetric cipher's IV of 128-bit. */
  20. #define CIPHER_IV_LEN 16
  21. /** Length of our symmetric cipher's keys of 256-bit. */
  22. #define CIPHER256_KEY_LEN 32
  23. /** Length of encoded public key fingerprints, including space; but not
  24. * including terminating NUL. */
  25. #define FINGERPRINT_LEN 49
  26. typedef struct aes_cnt_cipher crypto_cipher_t;
  27. /* environment setup */
  28. crypto_cipher_t *crypto_cipher_new(const char *key);
  29. crypto_cipher_t *crypto_cipher_new_with_bits(const char *key, int bits);
  30. crypto_cipher_t *crypto_cipher_new_with_iv(const char *key, const char *iv);
  31. crypto_cipher_t *crypto_cipher_new_with_iv_and_bits(const uint8_t *key,
  32. const uint8_t *iv,
  33. int bits);
  34. void crypto_cipher_free_(crypto_cipher_t *env);
  35. #define crypto_cipher_free(c) \
  36. FREE_AND_NULL(crypto_cipher_t, crypto_cipher_free_, (c))
  37. /* symmetric crypto */
  38. const char *crypto_cipher_get_key(crypto_cipher_t *env);
  39. int crypto_cipher_encrypt(crypto_cipher_t *env, char *to,
  40. const char *from, size_t fromlen);
  41. int crypto_cipher_decrypt(crypto_cipher_t *env, char *to,
  42. const char *from, size_t fromlen);
  43. void crypto_cipher_crypt_inplace(crypto_cipher_t *env, char *d, size_t len);
  44. int crypto_cipher_encrypt_with_iv(const char *key,
  45. char *to, size_t tolen,
  46. const char *from, size_t fromlen);
  47. int crypto_cipher_decrypt_with_iv(const char *key,
  48. char *to, size_t tolen,
  49. const char *from, size_t fromlen);
  50. void crypto_add_spaces_to_fp(char *out, size_t outlen, const char *in);
  51. #endif /* !defined(TOR_CRYPTO_H) */