2007-12-12 21:09:01 +00:00
|
|
|
/* Copyright (c) 2001, Matej Pfajfar.
|
2006-02-09 05:46:49 +00:00
|
|
|
* Copyright (c) 2001-2004, Roger Dingledine.
|
2007-12-12 21:09:01 +00:00
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2017-03-15 16:13:17 -04:00
|
|
|
* Copyright (c) 2007-2017, The Tor Project, Inc. */
|
2002-07-24 14:02:39 +00:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
2004-05-10 03:53:24 +00:00
|
|
|
/**
|
2004-05-10 07:54:13 +00:00
|
|
|
* \file crypto.h
|
2004-05-10 03:53:24 +00:00
|
|
|
*
|
2005-06-11 05:31:17 +00:00
|
|
|
* \brief Headers for crypto.c
|
2004-05-10 03:53:24 +00:00
|
|
|
**/
|
|
|
|
|
2012-10-12 12:13:10 -04:00
|
|
|
#ifndef TOR_CRYPTO_H
|
|
|
|
#define TOR_CRYPTO_H
|
2002-07-24 14:02:39 +00:00
|
|
|
|
2016-07-28 10:47:46 -04:00
|
|
|
#include "orconfig.h"
|
|
|
|
|
2002-08-22 07:30:03 +00:00
|
|
|
#include <stdio.h>
|
2006-10-01 21:59:05 +00:00
|
|
|
#include "torint.h"
|
2015-11-25 10:30:58 -05:00
|
|
|
#include "compat.h"
|
2017-11-17 11:55:52 -05:00
|
|
|
#include "util.h"
|
2018-01-25 20:16:50 +01:00
|
|
|
#include "crypto_rsa.h"
|
2002-07-24 14:02:39 +00:00
|
|
|
|
2016-11-07 13:15:46 -05:00
|
|
|
/** Length of our symmetric cipher's keys of 128-bit. */
|
2004-04-03 02:40:30 +00:00
|
|
|
#define CIPHER_KEY_LEN 16
|
2016-11-07 13:15:46 -05:00
|
|
|
/** Length of our symmetric cipher's IV of 128-bit. */
|
2007-09-19 15:53:41 +00:00
|
|
|
#define CIPHER_IV_LEN 16
|
2016-11-07 13:15:46 -05:00
|
|
|
/** Length of our symmetric cipher's keys of 256-bit. */
|
|
|
|
#define CIPHER256_KEY_LEN 32
|
2003-12-16 05:29:04 +00:00
|
|
|
|
2004-05-10 03:53:24 +00:00
|
|
|
/** Length of encoded public key fingerprints, including space; but not
|
2004-05-01 21:41:23 +00:00
|
|
|
* including terminating NUL. */
|
2004-05-01 20:46:28 +00:00
|
|
|
#define FINGERPRINT_LEN 49
|
|
|
|
|
2016-09-16 10:18:02 -04:00
|
|
|
typedef struct aes_cnt_cipher crypto_cipher_t;
|
2002-07-24 14:02:39 +00:00
|
|
|
|
|
|
|
/* global state */
|
2018-04-18 19:16:32 +00:00
|
|
|
int crypto_init_siphash_key(void);
|
2015-11-25 10:36:34 -05:00
|
|
|
int crypto_early_init(void) ATTR_WUR;
|
2009-05-23 16:42:44 -07:00
|
|
|
int crypto_global_init(int hardwareAccel,
|
|
|
|
const char *accelName,
|
2015-11-25 10:36:34 -05:00
|
|
|
const char *accelPath) ATTR_WUR;
|
2017-03-25 11:27:50 +01:00
|
|
|
#ifdef USE_DMALLOC
|
|
|
|
int crypto_use_tor_alloc_functions(void);
|
|
|
|
#endif
|
|
|
|
|
2005-10-25 19:01:48 +00:00
|
|
|
void crypto_thread_cleanup(void);
|
2004-10-27 18:16:37 +00:00
|
|
|
int crypto_global_cleanup(void);
|
2002-07-24 14:02:39 +00:00
|
|
|
|
|
|
|
/* environment setup */
|
2012-03-20 15:35:43 -04:00
|
|
|
crypto_cipher_t *crypto_cipher_new(const char *key);
|
2016-09-16 11:21:33 -04:00
|
|
|
crypto_cipher_t *crypto_cipher_new_with_bits(const char *key, int bits);
|
2012-03-20 15:35:43 -04:00
|
|
|
crypto_cipher_t *crypto_cipher_new_with_iv(const char *key, const char *iv);
|
2016-09-16 11:21:33 -04:00
|
|
|
crypto_cipher_t *crypto_cipher_new_with_iv_and_bits(const uint8_t *key,
|
|
|
|
const uint8_t *iv,
|
|
|
|
int bits);
|
2017-11-17 11:55:52 -05:00
|
|
|
void crypto_cipher_free_(crypto_cipher_t *env);
|
2017-12-07 10:52:55 -05:00
|
|
|
#define crypto_cipher_free(c) \
|
|
|
|
FREE_AND_NULL(crypto_cipher_t, crypto_cipher_free_, (c))
|
2002-07-24 14:02:39 +00:00
|
|
|
|
|
|
|
/* symmetric crypto */
|
2012-01-18 15:53:30 -05:00
|
|
|
const char *crypto_cipher_get_key(crypto_cipher_t *env);
|
2002-07-24 14:02:39 +00:00
|
|
|
|
2012-01-18 15:53:30 -05:00
|
|
|
int crypto_cipher_encrypt(crypto_cipher_t *env, char *to,
|
2005-05-07 05:55:06 +00:00
|
|
|
const char *from, size_t fromlen);
|
2012-01-18 15:53:30 -05:00
|
|
|
int crypto_cipher_decrypt(crypto_cipher_t *env, char *to,
|
2005-05-07 05:55:06 +00:00
|
|
|
const char *from, size_t fromlen);
|
2016-02-06 12:14:39 -05:00
|
|
|
void crypto_cipher_crypt_inplace(crypto_cipher_t *env, char *d, size_t len);
|
2002-07-24 14:02:39 +00:00
|
|
|
|
2012-03-20 15:35:43 -04:00
|
|
|
int crypto_cipher_encrypt_with_iv(const char *key,
|
2007-09-19 15:53:41 +00:00
|
|
|
char *to, size_t tolen,
|
|
|
|
const char *from, size_t fromlen);
|
2012-03-20 15:35:43 -04:00
|
|
|
int crypto_cipher_decrypt_with_iv(const char *key,
|
2007-09-19 15:53:41 +00:00
|
|
|
char *to, size_t tolen,
|
|
|
|
const char *from, size_t fromlen);
|
|
|
|
|
2013-06-06 17:58:28 -04:00
|
|
|
void crypto_add_spaces_to_fp(char *out, size_t outlen, const char *in);
|
2007-04-30 22:42:50 +00:00
|
|
|
|
2017-09-15 16:24:44 -04:00
|
|
|
#endif /* !defined(TOR_CRYPTO_H) */
|
2015-10-02 14:33:54 +02:00
|
|
|
|