crypto_s2k.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_s2k.h
  8. *
  9. * \brief Header for crypto_s2k.c
  10. **/
  11. #ifndef TOR_CRYPTO_S2K_H_INCLUDED
  12. #define TOR_CRYPTO_S2K_H_INCLUDED
  13. #include <stdio.h>
  14. #include "lib/cc/torint.h"
  15. /** Length of RFC2440-style S2K specifier: the first 8 bytes are a salt, the
  16. * 9th describes how much iteration to do. */
  17. #define S2K_RFC2440_SPECIFIER_LEN 9
  18. void secret_to_key_rfc2440(
  19. char *key_out, size_t key_out_len, const char *secret,
  20. size_t secret_len, const char *s2k_specifier);
  21. /** Flag for secret-to-key function: do not use scrypt. */
  22. #define S2K_FLAG_NO_SCRYPT (1u<<0)
  23. /** Flag for secret-to-key functions: if using a memory-tuned s2k function,
  24. * assume that we have limited memory. */
  25. #define S2K_FLAG_LOW_MEM (1u<<1)
  26. /** Flag for secret-to-key functions: force use of pbkdf2. Without this, we
  27. * default to scrypt, then RFC2440. */
  28. #define S2K_FLAG_USE_PBKDF2 (1u<<2)
  29. /** Maximum possible output length from secret_to_key_new. */
  30. #define S2K_MAXLEN 64
  31. /** Error code from secret-to-key functions: all is well */
  32. #define S2K_OKAY 0
  33. /** Error code from secret-to-key functions: generic failure */
  34. #define S2K_FAILED -1
  35. /** Error code from secret-to-key functions: provided secret didn't match */
  36. #define S2K_BAD_SECRET -2
  37. /** Error code from secret-to-key functions: didn't recognize the algorithm */
  38. #define S2K_BAD_ALGORITHM -3
  39. /** Error code from secret-to-key functions: specifier wasn't valid */
  40. #define S2K_BAD_PARAMS -4
  41. /** Error code from secret-to-key functions: compiled without scrypt */
  42. #define S2K_NO_SCRYPT_SUPPORT -5
  43. /** Error code from secret-to-key functions: not enough space to write output.
  44. */
  45. #define S2K_TRUNCATED -6
  46. /** Error code from secret-to-key functions: Wrong length for specifier. */
  47. #define S2K_BAD_LEN -7
  48. int secret_to_key_new(uint8_t *buf,
  49. size_t buf_len,
  50. size_t *len_out,
  51. const char *secret, size_t secret_len,
  52. unsigned flags);
  53. int secret_to_key_make_specifier(uint8_t *buf, size_t buf_len, unsigned flags);
  54. int secret_to_key_check(const uint8_t *spec_and_key, size_t spec_and_key_len,
  55. const char *secret, size_t secret_len);
  56. int secret_to_key_derivekey(uint8_t *key_out, size_t key_out_len,
  57. const uint8_t *spec, size_t spec_len,
  58. const char *secret, size_t secret_len);
  59. #ifdef CRYPTO_S2K_PRIVATE
  60. STATIC int secret_to_key_compute_key(uint8_t *key_out, size_t key_out_len,
  61. const uint8_t *spec, size_t spec_len,
  62. const char *secret, size_t secret_len,
  63. int type);
  64. #endif /* defined(CRYPTO_S2K_PRIVATE) */
  65. #endif /* !defined(TOR_CRYPTO_S2K_H_INCLUDED) */