tor  0.4.2.0-alpha-dev
crypto_s2k.h
Go to the documentation of this file.
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 
13 #ifndef TOR_CRYPTO_S2K_H_INCLUDED
14 #define TOR_CRYPTO_S2K_H_INCLUDED
15 
16 #include <stdio.h>
17 #include "lib/cc/torint.h"
18 
21 #define S2K_RFC2440_SPECIFIER_LEN 9
23  char *key_out, size_t key_out_len, const char *secret,
24  size_t secret_len, const char *s2k_specifier);
25 
27 #define S2K_FLAG_NO_SCRYPT (1u<<0)
28 
30 #define S2K_FLAG_LOW_MEM (1u<<1)
31 
33 #define S2K_FLAG_USE_PBKDF2 (1u<<2)
34 
36 #define S2K_MAXLEN 64
37 
39 #define S2K_OKAY 0
40 
41 #define S2K_FAILED -1
42 
43 #define S2K_BAD_SECRET -2
44 
45 #define S2K_BAD_ALGORITHM -3
46 
47 #define S2K_BAD_PARAMS -4
48 
49 #define S2K_NO_SCRYPT_SUPPORT -5
50 
52 #define S2K_TRUNCATED -6
53 
54 #define S2K_BAD_LEN -7
55 
56 int secret_to_key_new(uint8_t *buf,
57  size_t buf_len,
58  size_t *len_out,
59  const char *secret, size_t secret_len,
60  unsigned flags);
61 
62 int secret_to_key_make_specifier(uint8_t *buf, size_t buf_len, unsigned flags);
63 
64 int secret_to_key_check(const uint8_t *spec_and_key, size_t spec_and_key_len,
65  const char *secret, size_t secret_len);
66 
67 int secret_to_key_derivekey(uint8_t *key_out, size_t key_out_len,
68  const uint8_t *spec, size_t spec_len,
69  const char *secret, size_t secret_len);
70 
71 #ifdef CRYPTO_S2K_PRIVATE
72 STATIC int secret_to_key_compute_key(uint8_t *key_out, size_t key_out_len,
73  const uint8_t *spec, size_t spec_len,
74  const char *secret, size_t secret_len,
75  int type);
76 #endif /* defined(CRYPTO_S2K_PRIVATE) */
77 
78 #endif /* !defined(TOR_CRYPTO_S2K_H_INCLUDED) */
STATIC int secret_to_key_compute_key(uint8_t *key_out, size_t key_out_len, const uint8_t *spec, size_t spec_len, const char *secret, size_t secret_len, int type)
Definition: crypto_s2k.c:258
int secret_to_key_new(uint8_t *buf, size_t buf_len, size_t *len_out, const char *secret, size_t secret_len, unsigned flags)
Definition: crypto_s2k.c:442
Integer definitions used throughout Tor.
void secret_to_key_rfc2440(char *key_out, size_t key_out_len, const char *secret, size_t secret_len, const char *s2k_specifier)
Definition: crypto_s2k.c:203
int secret_to_key_check(const uint8_t *spec_and_key, size_t spec_and_key_len, const char *secret, size_t secret_len)
Definition: crypto_s2k.c:486
int secret_to_key_make_specifier(uint8_t *buf, size_t buf_len, unsigned flags)
Definition: crypto_s2k.c:405
int secret_to_key_derivekey(uint8_t *key_out, size_t key_out_len, const uint8_t *spec, size_t spec_len, const char *secret, size_t secret_len)
Definition: crypto_s2k.c:370