tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

crypto_s2k.h (3062B)


      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-2021, The Tor Project, Inc. */
      5 /* See LICENSE for licensing information */
      6 
      7 /**
      8 * \file crypto_s2k.h
      9 *
     10 * \brief Header for crypto_s2k.c
     11 **/
     12 
     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 
     19 /** Length of RFC2440-style S2K specifier: the first 8 bytes are a salt, the
     20 * 9th describes how much iteration to do. */
     21 #define S2K_RFC2440_SPECIFIER_LEN 9
     22 void secret_to_key_rfc2440(
     23                   char *key_out, size_t key_out_len, const char *secret,
     24                   size_t secret_len, const char *s2k_specifier);
     25 
     26 /** Flag for secret-to-key function: do not use scrypt. */
     27 #define S2K_FLAG_NO_SCRYPT  (1u<<0)
     28 /** Flag for secret-to-key functions: if using a memory-tuned s2k function,
     29 * assume that we have limited memory. */
     30 #define S2K_FLAG_LOW_MEM    (1u<<1)
     31 /** Flag for secret-to-key functions: force use of pbkdf2.  Without this, we
     32 * default to scrypt, then RFC2440. */
     33 #define S2K_FLAG_USE_PBKDF2 (1u<<2)
     34 
     35 /** Maximum possible output length from secret_to_key_new. */
     36 #define S2K_MAXLEN 64
     37 
     38 /** Error code from secret-to-key functions: all is well */
     39 #define S2K_OKAY 0
     40 /** Error code from secret-to-key functions: generic failure */
     41 #define S2K_FAILED -1
     42 /** Error code from secret-to-key functions: provided secret didn't match */
     43 #define S2K_BAD_SECRET -2
     44 /** Error code from secret-to-key functions: didn't recognize the algorithm */
     45 #define S2K_BAD_ALGORITHM -3
     46 /** Error code from secret-to-key functions: specifier wasn't valid */
     47 #define S2K_BAD_PARAMS -4
     48 /** Error code from secret-to-key functions: compiled without scrypt */
     49 #define S2K_NO_SCRYPT_SUPPORT -5
     50 /** Error code from secret-to-key functions: not enough space to write output.
     51 */
     52 #define S2K_TRUNCATED -6
     53 /** Error code from secret-to-key functions: Wrong length for specifier. */
     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) */