crypto.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. /* global state */
  28. int crypto_init_siphash_key(void);
  29. int crypto_early_init(void) ATTR_WUR;
  30. int crypto_global_init(int hardwareAccel,
  31. const char *accelName,
  32. const char *accelPath) ATTR_WUR;
  33. void crypto_thread_cleanup(void);
  34. int crypto_global_cleanup(void);
  35. /* environment setup */
  36. crypto_cipher_t *crypto_cipher_new(const char *key);
  37. crypto_cipher_t *crypto_cipher_new_with_bits(const char *key, int bits);
  38. crypto_cipher_t *crypto_cipher_new_with_iv(const char *key, const char *iv);
  39. crypto_cipher_t *crypto_cipher_new_with_iv_and_bits(const uint8_t *key,
  40. const uint8_t *iv,
  41. int bits);
  42. void crypto_cipher_free_(crypto_cipher_t *env);
  43. #define crypto_cipher_free(c) \
  44. FREE_AND_NULL(crypto_cipher_t, crypto_cipher_free_, (c))
  45. /* symmetric crypto */
  46. const char *crypto_cipher_get_key(crypto_cipher_t *env);
  47. int crypto_cipher_encrypt(crypto_cipher_t *env, char *to,
  48. const char *from, size_t fromlen);
  49. int crypto_cipher_decrypt(crypto_cipher_t *env, char *to,
  50. const char *from, size_t fromlen);
  51. void crypto_cipher_crypt_inplace(crypto_cipher_t *env, char *d, size_t len);
  52. int crypto_cipher_encrypt_with_iv(const char *key,
  53. char *to, size_t tolen,
  54. const char *from, size_t fromlen);
  55. int crypto_cipher_decrypt_with_iv(const char *key,
  56. char *to, size_t tolen,
  57. const char *from, size_t fromlen);
  58. void crypto_add_spaces_to_fp(char *out, size_t outlen, const char *in);
  59. #endif /* !defined(TOR_CRYPTO_H) */