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