Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
David Goulet
Tor
Commits
10b2208d
Commit
10b2208d
authored
May 07, 2005
by
Nick Mathewson
⛰
Browse files
Make Tor compile with no warnings with gcc4.0 on OSX
svn:r4184
parent
6567ec9c
Changes
17
Hide whitespace changes
Inline
Side-by-side
configure.in
View file @
10b2208d
...
...
@@ -186,6 +186,11 @@ AC_CHECK_SIZEOF(long long)
AC_CHECK_SIZEOF(__int64)
AC_CHECK_SIZEOF(void *)
AC_CHECK_SIZEOF(time_t)
AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
])
# We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
...
...
src/common/aes.c
View file @
10b2208d
...
...
@@ -84,9 +84,10 @@ aes_new_cipher()
* the counter to 0.
*/
void
aes_set_key
(
aes_cnt_cipher_t
*
cipher
,
const
unsigned
char
*
key
,
int
key_bits
)
aes_set_key
(
aes_cnt_cipher_t
*
cipher
,
const
char
*
key
,
int
key_bits
)
{
cipher
->
nr
=
rijndaelKeySetupEnc
(
cipher
->
rk
,
key
,
key_bits
);
cipher
->
nr
=
rijndaelKeySetupEnc
(
cipher
->
rk
,
(
const
unsigned
char
*
)
key
,
key_bits
);
cipher
->
counter0
=
0
;
cipher
->
counter1
=
0
;
cipher
->
pos
=
0
;
...
...
@@ -108,7 +109,7 @@ aes_free_cipher(aes_cnt_cipher_t *cipher)
* by <b>len</b> bytes as it encrypts.
*/
void
aes_crypt
(
aes_cnt_cipher_t
*
cipher
,
const
char
*
input
,
in
t
len
,
char
*
output
)
aes_crypt
(
aes_cnt_cipher_t
*
cipher
,
const
char
*
input
,
size_
t
len
,
char
*
output
)
{
int
c
=
cipher
->
pos
;
if
(
!
len
)
return
;
...
...
src/common/aes.h
View file @
10b2208d
...
...
@@ -21,8 +21,8 @@ typedef struct aes_cnt_cipher aes_cnt_cipher_t;
aes_cnt_cipher_t
*
aes_new_cipher
(
void
);
void
aes_free_cipher
(
aes_cnt_cipher_t
*
cipher
);
void
aes_set_key
(
aes_cnt_cipher_t
*
cipher
,
const
unsigned
char
*
key
,
int
key_bits
);
void
aes_crypt
(
aes_cnt_cipher_t
*
cipher
,
const
char
*
input
,
in
t
len
,
char
*
output
);
void
aes_set_key
(
aes_cnt_cipher_t
*
cipher
,
const
char
*
key
,
int
key_bits
);
void
aes_crypt
(
aes_cnt_cipher_t
*
cipher
,
const
char
*
input
,
size_
t
len
,
char
*
output
);
uint64_t
aes_get_counter
(
aes_cnt_cipher_t
*
cipher
);
void
aes_set_counter
(
aes_cnt_cipher_t
*
cipher
,
uint64_t
counter
);
void
aes_adjust_counter
(
aes_cnt_cipher_t
*
cipher
,
long
delta
);
...
...
src/common/compat.h
View file @
10b2208d
...
...
@@ -135,6 +135,10 @@ int replace_file(const char *from, const char *to);
#define tor_close_socket(s) close(s)
#endif
#if (SIZEOF_SOCKLEN_T == 0)
typedef
int
socklen_t
;
#endif
/* Now that we use libevent, all real sockets are safe for polling ... or
* if they aren't, libevent will help us. */
#define SOCKET_IS_POLLABLE(fd) ((fd)>=0)
...
...
src/common/crypto.c
View file @
10b2208d
...
...
@@ -93,7 +93,7 @@ struct crypto_pk_env_t
struct
crypto_cipher_env_t
{
unsigned
char
key
[
CIPHER_KEY_LEN
];
char
key
[
CIPHER_KEY_LEN
];
aes_cnt_cipher_t
*
cipher
;
};
...
...
@@ -597,12 +597,12 @@ int crypto_pk_cmp_keys(crypto_pk_env_t *a, crypto_pk_env_t *b) {
}
/** Return the size of the public key modulus in <b>env</b>, in bytes. */
in
t
crypto_pk_keysize
(
crypto_pk_env_t
*
env
)
size_
t
crypto_pk_keysize
(
crypto_pk_env_t
*
env
)
{
tor_assert
(
env
);
tor_assert
(
env
->
key
);
return
RSA_size
(
env
->
key
);
return
(
size_t
)
RSA_size
(
env
->
key
);
}
/** Increase the reference count of <b>env</b>, and return it.
...
...
@@ -621,16 +621,16 @@ crypto_pk_env_t *crypto_pk_dup_key(crypto_pk_env_t *env) {
* written. On failure, return -1.
*/
int
crypto_pk_public_encrypt
(
crypto_pk_env_t
*
env
,
unsigned
char
*
to
,
const
unsigned
char
*
from
,
in
t
fromlen
,
int
padding
)
crypto_pk_public_encrypt
(
crypto_pk_env_t
*
env
,
char
*
to
,
const
char
*
from
,
size_
t
fromlen
,
int
padding
)
{
int
r
;
tor_assert
(
env
);
tor_assert
(
from
);
tor_assert
(
to
);
r
=
RSA_public_encrypt
(
fromlen
,
(
unsigned
char
*
)
from
,
to
,
env
->
key
,
crypto_get_rsa_padding
(
padding
));
r
=
RSA_public_encrypt
(
fromlen
,
(
unsigned
char
*
)
from
,
(
unsigned
char
*
)
to
,
env
->
key
,
crypto_get_rsa_padding
(
padding
));
if
(
r
<
0
)
{
crypto_log_errors
(
LOG_WARN
,
"performing RSA encryption"
);
return
-
1
;
...
...
@@ -644,8 +644,8 @@ crypto_pk_public_encrypt(crypto_pk_env_t *env, unsigned char *to,
* written. On failure, return -1.
*/
int
crypto_pk_private_decrypt
(
crypto_pk_env_t
*
env
,
unsigned
char
*
to
,
const
unsigned
char
*
from
,
in
t
fromlen
,
crypto_pk_private_decrypt
(
crypto_pk_env_t
*
env
,
char
*
to
,
const
char
*
from
,
size_
t
fromlen
,
int
padding
,
int
warnOnFailure
)
{
int
r
;
...
...
@@ -657,8 +657,9 @@ crypto_pk_private_decrypt(crypto_pk_env_t *env, unsigned char *to,
/* Not a private key */
return
-
1
;
r
=
RSA_private_decrypt
(
fromlen
,
(
unsigned
char
*
)
from
,
to
,
env
->
key
,
crypto_get_rsa_padding
(
padding
));
r
=
RSA_private_decrypt
(
fromlen
,
(
unsigned
char
*
)
from
,
(
unsigned
char
*
)
to
,
env
->
key
,
crypto_get_rsa_padding
(
padding
));
if
(
r
<
0
)
{
crypto_log_errors
(
warnOnFailure
?
LOG_WARN
:
LOG_INFO
,
"performing RSA decryption"
);
...
...
@@ -673,14 +674,14 @@ crypto_pk_private_decrypt(crypto_pk_env_t *env, unsigned char *to,
* On failure, return -1.
*/
int
crypto_pk_public_checksig
(
crypto_pk_env_t
*
env
,
unsigned
char
*
to
,
const
unsigned
char
*
from
,
in
t
fromlen
)
crypto_pk_public_checksig
(
crypto_pk_env_t
*
env
,
char
*
to
,
const
char
*
from
,
size_
t
fromlen
)
{
int
r
;
tor_assert
(
env
);
tor_assert
(
from
);
tor_assert
(
to
);
r
=
RSA_public_decrypt
(
fromlen
,
(
unsigned
char
*
)
from
,
to
,
env
->
key
,
RSA_PKCS1_PADDING
);
r
=
RSA_public_decrypt
(
fromlen
,
(
unsigned
char
*
)
from
,
(
unsigned
char
*
)
to
,
env
->
key
,
RSA_PKCS1_PADDING
);
if
(
r
<
0
)
{
crypto_log_errors
(
LOG_WARN
,
"checking RSA signature"
);
...
...
@@ -695,8 +696,8 @@ crypto_pk_public_checksig(crypto_pk_env_t *env, unsigned char *to,
* SHA1(data). Else return -1.
*/
int
crypto_pk_public_checksig_digest
(
crypto_pk_env_t
*
env
,
const
unsigned
char
*
data
,
int
datalen
,
const
unsigned
char
*
sig
,
int
siglen
)
crypto_pk_public_checksig_digest
(
crypto_pk_env_t
*
env
,
const
char
*
data
,
int
datalen
,
const
char
*
sig
,
int
siglen
)
{
char
digest
[
DIGEST_LEN
];
char
buf
[
PK_BYTES
+
1
];
...
...
@@ -729,8 +730,8 @@ crypto_pk_public_checksig_digest(crypto_pk_env_t *env, const unsigned char *data
* -1.
*/
int
crypto_pk_private_sign
(
crypto_pk_env_t
*
env
,
unsigned
char
*
to
,
const
unsigned
char
*
from
,
in
t
fromlen
)
crypto_pk_private_sign
(
crypto_pk_env_t
*
env
,
char
*
to
,
const
char
*
from
,
size_
t
fromlen
)
{
int
r
;
tor_assert
(
env
);
...
...
@@ -740,7 +741,7 @@ crypto_pk_private_sign(crypto_pk_env_t *env, unsigned char *to,
/* Not a private key */
return
-
1
;
r
=
RSA_private_encrypt
(
fromlen
,
(
unsigned
char
*
)
from
,
to
,
env
->
key
,
RSA_PKCS1_PADDING
);
r
=
RSA_private_encrypt
(
fromlen
,
(
unsigned
char
*
)
from
,
(
unsigned
char
*
)
to
,
env
->
key
,
RSA_PKCS1_PADDING
);
if
(
r
<
0
)
{
crypto_log_errors
(
LOG_WARN
,
"generating RSA signature"
);
return
-
1
;
...
...
@@ -754,8 +755,8 @@ crypto_pk_private_sign(crypto_pk_env_t *env, unsigned char *to,
* success, and -1 on failure.
*/
int
crypto_pk_private_sign_digest
(
crypto_pk_env_t
*
env
,
unsigned
char
*
to
,
const
unsigned
char
*
from
,
in
t
fromlen
)
crypto_pk_private_sign_digest
(
crypto_pk_env_t
*
env
,
char
*
to
,
const
char
*
from
,
size_
t
fromlen
)
{
char
digest
[
DIGEST_LEN
];
if
(
crypto_digest
(
digest
,
from
,
fromlen
)
<
0
)
...
...
@@ -781,12 +782,13 @@ crypto_pk_private_sign_digest(crypto_pk_env_t *env, unsigned char *to,
* the source data encrypted in AES-CTR mode with the symmetric key.
*/
int
crypto_pk_public_hybrid_encrypt
(
crypto_pk_env_t
*
env
,
unsigned
char
*
to
,
const
unsigned
char
*
from
,
in
t
fromlen
,
char
*
to
,
const
char
*
from
,
size_
t
fromlen
,
int
padding
,
int
force
)
{
int
overhead
,
pkeylen
,
outlen
,
r
,
symlen
;
int
overhead
,
outlen
,
r
,
symlen
;
size_t
pkeylen
;
crypto_cipher_env_t
*
cipher
=
NULL
;
char
buf
[
PK_BYTES
+
1
];
...
...
@@ -825,7 +827,7 @@ int crypto_pk_public_hybrid_encrypt(crypto_pk_env_t *env,
symlen
=
fromlen
-
(
pkeylen
-
overhead
-
CIPHER_KEY_LEN
);
outlen
=
crypto_pk_public_encrypt
(
env
,
to
,
buf
,
pkeylen
-
overhead
,
padding
);
if
(
outlen
!=
pkeylen
)
{
if
(
outlen
!=
(
int
)
pkeylen
)
{
goto
err
;
}
r
=
crypto_cipher_encrypt
(
cipher
,
to
+
outlen
,
...
...
@@ -843,12 +845,13 @@ int crypto_pk_public_hybrid_encrypt(crypto_pk_env_t *env,
/** Invert crypto_pk_public_hybrid_encrypt. */
int
crypto_pk_private_hybrid_decrypt
(
crypto_pk_env_t
*
env
,
unsigned
char
*
to
,
const
unsigned
char
*
from
,
in
t
fromlen
,
char
*
to
,
const
char
*
from
,
size_
t
fromlen
,
int
padding
,
int
warnOnFailure
)
{
int
overhead
,
pkeylen
,
outlen
,
r
;
int
overhead
,
outlen
,
r
;
size_t
pkeylen
;
crypto_cipher_env_t
*
cipher
=
NULL
;
char
buf
[
PK_BYTES
+
1
];
...
...
@@ -913,7 +916,7 @@ int crypto_pk_asn1_encode(crypto_pk_env_t *pk, char *dest, int dest_len)
/** Decode an ASN.1-encoded public key from <b>str</b>; return the result on
* success and NULL on failure.
*/
crypto_pk_env_t
*
crypto_pk_asn1_decode
(
const
char
*
str
,
in
t
len
)
crypto_pk_env_t
*
crypto_pk_asn1_decode
(
const
char
*
str
,
size_
t
len
)
{
RSA
*
rsa
;
unsigned
char
*
buf
;
...
...
@@ -955,7 +958,7 @@ int crypto_pk_get_digest(crypto_pk_env_t *pk, char *digest_out)
free
(
buf
);
return
-
1
;
}
if
(
crypto_digest
(
digest_out
,
buf
,
len
)
<
0
)
{
if
(
crypto_digest
(
digest_out
,
(
char
*
)
buf
,
len
)
<
0
)
{
free
(
buf
);
return
-
1
;
}
...
...
@@ -976,8 +979,8 @@ int crypto_pk_get_digest(crypto_pk_env_t *pk, char *digest_out)
int
crypto_pk_get_fingerprint
(
crypto_pk_env_t
*
pk
,
char
*
fp_out
,
int
add_space
)
{
unsigned
char
digest
[
DIGEST_LEN
];
unsigned
char
hexdigest
[
HEX_DIGEST_LEN
+
1
];
char
digest
[
DIGEST_LEN
];
char
hexdigest
[
HEX_DIGEST_LEN
+
1
];
if
(
crypto_pk_get_digest
(
pk
,
digest
))
{
return
-
1
;
}
...
...
@@ -1025,7 +1028,7 @@ int crypto_cipher_generate_key(crypto_cipher_env_t *env)
* CIPHER_KEY_LEN bytes of <b>key</b>. Does not initialize the cipher.
* Return 0 on success, -1 on failure.
*/
int
crypto_cipher_set_key
(
crypto_cipher_env_t
*
env
,
const
unsigned
char
*
key
)
int
crypto_cipher_set_key
(
crypto_cipher_env_t
*
env
,
const
char
*
key
)
{
tor_assert
(
env
);
tor_assert
(
key
);
...
...
@@ -1040,7 +1043,7 @@ int crypto_cipher_set_key(crypto_cipher_env_t *env, const unsigned char *key)
/** Return a pointer to the key set for the cipher in <b>env</b>.
*/
const
unsigned
char
*
crypto_cipher_get_key
(
crypto_cipher_env_t
*
env
)
const
char
*
crypto_cipher_get_key
(
crypto_cipher_env_t
*
env
)
{
return
env
->
key
;
}
...
...
@@ -1072,8 +1075,8 @@ int crypto_cipher_decrypt_init_cipher(crypto_cipher_env_t *env)
* On failure, return -1.
*/
int
crypto_cipher_encrypt
(
crypto_cipher_env_t
*
env
,
unsigned
char
*
to
,
const
unsigned
char
*
from
,
unsigned
in
t
fromlen
)
crypto_cipher_encrypt
(
crypto_cipher_env_t
*
env
,
char
*
to
,
const
char
*
from
,
size_
t
fromlen
)
{
tor_assert
(
env
);
tor_assert
(
env
->
cipher
);
...
...
@@ -1090,8 +1093,8 @@ crypto_cipher_encrypt(crypto_cipher_env_t *env, unsigned char *to,
* On failure, return -1.
*/
int
crypto_cipher_decrypt
(
crypto_cipher_env_t
*
env
,
unsigned
char
*
to
,
const
unsigned
char
*
from
,
unsigned
in
t
fromlen
)
crypto_cipher_decrypt
(
crypto_cipher_env_t
*
env
,
char
*
to
,
const
char
*
from
,
size_
t
fromlen
)
{
tor_assert
(
env
);
tor_assert
(
from
);
...
...
@@ -1126,11 +1129,11 @@ crypto_cipher_advance(crypto_cipher_env_t *env, long delta)
* <b>m</b>. Write the DIGEST_LEN byte result into <b>digest</b>.
* Return 0 on success, -1 on failure.
*/
int
crypto_digest
(
unsigned
char
*
digest
,
const
unsigned
char
*
m
,
in
t
len
)
int
crypto_digest
(
char
*
digest
,
const
char
*
m
,
size_
t
len
)
{
tor_assert
(
m
);
tor_assert
(
digest
);
return
(
SHA1
(
m
,
len
,
digest
)
==
NULL
);
return
(
SHA1
(
(
const
unsigned
char
*
)
m
,
len
,(
unsigned
char
*
)
digest
)
==
NULL
);
}
struct
crypto_digest_env_t
{
...
...
@@ -1178,7 +1181,7 @@ crypto_digest_add_bytes(crypto_digest_env_t *digest, const char *data,
void
crypto_digest_get_digest
(
crypto_digest_env_t
*
digest
,
char
*
out
,
size_t
out_len
)
{
static
char
r
[
DIGEST_LEN
];
static
unsigned
char
r
[
DIGEST_LEN
];
SHA_CTX
tmpctx
;
tor_assert
(
digest
);
tor_assert
(
out
);
...
...
@@ -1337,7 +1340,7 @@ int crypto_dh_get_public(crypto_dh_env_t *dh, char *pubkey, size_t pubkey_len)
return
-
1
;
memset
(
pubkey
,
0
,
pubkey_len
);
BN_bn2bin
(
dh
->
dh
->
pub_key
,
pubkey
+
(
pubkey_len
-
bytes
));
BN_bn2bin
(
dh
->
dh
->
pub_key
,
(
unsigned
char
*
)(
pubkey
+
(
pubkey_len
-
bytes
))
)
;
return
0
;
}
...
...
@@ -1358,8 +1361,8 @@ int crypto_dh_compute_secret(crypto_dh_env_t *dh,
const
char
*
pubkey
,
size_t
pubkey_len
,
char
*
secret_out
,
size_t
secret_bytes_out
)
{
unsigned
char
hash
[
DIGEST_LEN
];
unsigned
char
*
secret_tmp
=
NULL
;
char
hash
[
DIGEST_LEN
];
char
*
secret_tmp
=
NULL
;
BIGNUM
*
pubkey_bn
=
NULL
;
size_t
secret_len
=
0
;
unsigned
int
i
;
...
...
@@ -1367,10 +1370,10 @@ int crypto_dh_compute_secret(crypto_dh_env_t *dh,
tor_assert
(
dh
);
tor_assert
(
secret_bytes_out
/
DIGEST_LEN
<=
255
);
if
(
!
(
pubkey_bn
=
BN_bin2bn
(
pubkey
,
pubkey_len
,
NULL
)))
if
(
!
(
pubkey_bn
=
BN_bin2bn
(
(
const
unsigned
char
*
)
pubkey
,
pubkey_len
,
NULL
)))
goto
error
;
secret_tmp
=
tor_malloc
(
crypto_dh_get_bytes
(
dh
)
+
1
);
result
=
DH_compute_key
(
secret_tmp
,
pubkey_bn
,
dh
->
dh
);
result
=
DH_compute_key
(
(
unsigned
char
*
)
secret_tmp
,
pubkey_bn
,
dh
->
dh
);
if
(
result
<
0
)
{
log_fn
(
LOG_WARN
,
"DH_compute_key() failed."
);
goto
error
;
...
...
@@ -1475,11 +1478,11 @@ int crypto_seed_rng(void)
/** Write n bytes of strong random data to <b>to</b>. Return 0 on
* success, -1 on failure.
*/
int
crypto_rand
(
unsigned
char
*
to
,
unsigned
in
t
n
)
int
crypto_rand
(
char
*
to
,
size_
t
n
)
{
int
r
;
tor_assert
(
to
);
r
=
RAND_bytes
(
to
,
n
);
r
=
RAND_bytes
(
(
unsigned
char
*
)
to
,
n
);
if
(
r
==
0
)
crypto_log_errors
(
LOG_WARN
,
"generating random data"
);
return
(
r
==
1
)
?
0
:
-
1
;
...
...
@@ -1488,10 +1491,10 @@ int crypto_rand(unsigned char *to, unsigned int n)
/** Write n bytes of pseudorandom data to <b>to</b>. Return 0 on
* success, -1 on failure.
*/
void
crypto_pseudo_rand
(
unsigned
char
*
to
,
unsigned
in
t
n
)
void
crypto_pseudo_rand
(
char
*
to
,
size_
t
n
)
{
tor_assert
(
to
);
if
(
RAND_pseudo_bytes
(
to
,
n
)
==
-
1
)
{
if
(
RAND_pseudo_bytes
(
(
unsigned
char
*
)
to
,
n
)
==
-
1
)
{
log_fn
(
LOG_ERR
,
"RAND_pseudo_bytes failed unexpectedly."
);
crypto_log_errors
(
LOG_WARN
,
"generating random data"
);
exit
(
1
);
...
...
@@ -1512,7 +1515,7 @@ int crypto_pseudo_rand_int(unsigned int max) {
*/
cutoff
=
UINT_MAX
-
(
UINT_MAX
%
max
);
while
(
1
)
{
crypto_pseudo_rand
((
unsigned
char
*
)
&
val
,
sizeof
(
val
));
crypto_pseudo_rand
((
char
*
)
&
val
,
sizeof
(
val
));
if
(
val
<
cutoff
)
return
val
%
max
;
}
...
...
@@ -1548,8 +1551,8 @@ base64_encode(char *dest, size_t destlen, const char *src, size_t srclen)
return
-
1
;
EVP_EncodeInit
(
&
ctx
);
EVP_EncodeUpdate
(
&
ctx
,
dest
,
&
len
,
(
char
*
)
src
,
srclen
);
EVP_EncodeFinal
(
&
ctx
,
dest
+
len
,
&
ret
);
EVP_EncodeUpdate
(
&
ctx
,
(
unsigned
char
*
)
dest
,
&
len
,
(
unsigned
char
*
)
src
,
srclen
);
EVP_EncodeFinal
(
&
ctx
,
(
unsigned
char
*
)(
dest
+
len
)
,
&
ret
);
ret
+=
len
;
return
ret
;
}
...
...
@@ -1577,8 +1580,8 @@ base64_decode(char *dest, size_t destlen, const char *src, size_t srclen)
return
-
1
;
EVP_DecodeInit
(
&
ctx
);
EVP_DecodeUpdate
(
&
ctx
,
dest
,
&
len
,
(
char
*
)
src
,
srclen
);
EVP_DecodeFinal
(
&
ctx
,
dest
,
&
ret
);
EVP_DecodeUpdate
(
&
ctx
,
(
unsigned
char
*
)
dest
,
&
len
,
(
unsigned
char
*
)
src
,
srclen
);
EVP_DecodeFinal
(
&
ctx
,
(
unsigned
char
*
)
dest
,
&
ret
);
ret
+=
len
;
return
ret
;
}
...
...
src/common/crypto.h
View file @
10b2208d
...
...
@@ -73,53 +73,53 @@ crypto_pk_env_t *crypto_pk_DER64_decode_public_key(const char *in);
int
crypto_pk_check_key
(
crypto_pk_env_t
*
env
);
int
crypto_pk_cmp_keys
(
crypto_pk_env_t
*
a
,
crypto_pk_env_t
*
b
);
in
t
crypto_pk_keysize
(
crypto_pk_env_t
*
env
);
size_
t
crypto_pk_keysize
(
crypto_pk_env_t
*
env
);
crypto_pk_env_t
*
crypto_pk_dup_key
(
crypto_pk_env_t
*
orig
);
int
crypto_pk_public_encrypt
(
crypto_pk_env_t
*
env
,
unsigned
char
*
to
,
const
unsigned
char
*
from
,
in
t
fromlen
,
int
padding
);
int
crypto_pk_private_decrypt
(
crypto_pk_env_t
*
env
,
unsigned
char
*
to
,
const
unsigned
char
*
from
,
in
t
fromlen
,
int
crypto_pk_public_encrypt
(
crypto_pk_env_t
*
env
,
char
*
to
,
const
char
*
from
,
size_
t
fromlen
,
int
padding
);
int
crypto_pk_private_decrypt
(
crypto_pk_env_t
*
env
,
char
*
to
,
const
char
*
from
,
size_
t
fromlen
,
int
padding
,
int
warnOnFailure
);
int
crypto_pk_public_checksig
(
crypto_pk_env_t
*
env
,
unsigned
char
*
to
,
const
unsigned
char
*
from
,
in
t
fromlen
);
int
crypto_pk_public_checksig_digest
(
crypto_pk_env_t
*
env
,
const
unsigned
char
*
data
,
int
datalen
,
const
unsigned
char
*
sig
,
int
siglen
);
int
crypto_pk_private_sign
(
crypto_pk_env_t
*
env
,
unsigned
char
*
to
,
const
unsigned
char
*
from
,
in
t
fromlen
);
int
crypto_pk_private_sign_digest
(
crypto_pk_env_t
*
env
,
unsigned
char
*
to
,
const
unsigned
char
*
from
,
in
t
fromlen
);
int
crypto_pk_public_hybrid_encrypt
(
crypto_pk_env_t
*
env
,
unsigned
char
*
to
,
const
unsigned
char
*
from
,
in
t
fromlen
,
int
crypto_pk_public_checksig
(
crypto_pk_env_t
*
env
,
char
*
to
,
const
char
*
from
,
size_
t
fromlen
);
int
crypto_pk_public_checksig_digest
(
crypto_pk_env_t
*
env
,
const
char
*
data
,
int
datalen
,
const
char
*
sig
,
int
siglen
);
int
crypto_pk_private_sign
(
crypto_pk_env_t
*
env
,
char
*
to
,
const
char
*
from
,
size_
t
fromlen
);
int
crypto_pk_private_sign_digest
(
crypto_pk_env_t
*
env
,
char
*
to
,
const
char
*
from
,
size_
t
fromlen
);
int
crypto_pk_public_hybrid_encrypt
(
crypto_pk_env_t
*
env
,
char
*
to
,
const
char
*
from
,
size_
t
fromlen
,
int
padding
,
int
force
);
int
crypto_pk_private_hybrid_decrypt
(
crypto_pk_env_t
*
env
,
unsigned
char
*
to
,
const
unsigned
char
*
from
,
in
t
fromlen
,
int
crypto_pk_private_hybrid_decrypt
(
crypto_pk_env_t
*
env
,
char
*
to
,
const
char
*
from
,
size_
t
fromlen
,
int
padding
,
int
warnOnFailure
);
int
crypto_pk_asn1_encode
(
crypto_pk_env_t
*
pk
,
char
*
dest
,
int
dest_len
);
crypto_pk_env_t
*
crypto_pk_asn1_decode
(
const
char
*
str
,
in
t
len
);
crypto_pk_env_t
*
crypto_pk_asn1_decode
(
const
char
*
str
,
size_
t
len
);
int
crypto_pk_get_digest
(
crypto_pk_env_t
*
pk
,
char
*
digest_out
);
int
crypto_pk_get_fingerprint
(
crypto_pk_env_t
*
pk
,
char
*
fp_out
,
int
add_space
);
int
crypto_pk_check_fingerprint_syntax
(
const
char
*
s
);
/* symmetric crypto */
int
crypto_cipher_generate_key
(
crypto_cipher_env_t
*
env
);
int
crypto_cipher_set_key
(
crypto_cipher_env_t
*
env
,
const
unsigned
char
*
key
);
const
unsigned
char
*
crypto_cipher_get_key
(
crypto_cipher_env_t
*
env
);
int
crypto_cipher_set_key
(
crypto_cipher_env_t
*
env
,
const
char
*
key
);
const
char
*
crypto_cipher_get_key
(
crypto_cipher_env_t
*
env
);
int
crypto_cipher_encrypt_init_cipher
(
crypto_cipher_env_t
*
env
);
int
crypto_cipher_decrypt_init_cipher
(
crypto_cipher_env_t
*
env
);
int
crypto_cipher_encrypt
(
crypto_cipher_env_t
*
env
,
unsigned
char
*
to
,
const
unsigned
char
*
from
,
unsigned
in
t
fromlen
);
int
crypto_cipher_decrypt
(
crypto_cipher_env_t
*
env
,
unsigned
char
*
to
,
const
unsigned
char
*
from
,
unsigned
in
t
fromlen
);
int
crypto_cipher_encrypt
(
crypto_cipher_env_t
*
env
,
char
*
to
,
const
char
*
from
,
size_
t
fromlen
);
int
crypto_cipher_decrypt
(
crypto_cipher_env_t
*
env
,
char
*
to
,
const
char
*
from
,
size_
t
fromlen
);
/* only implemented for CRYPTO_CIPHER_AES_CTR */
int
crypto_cipher_rewind
(
crypto_cipher_env_t
*
env
,
long
delta
);
int
crypto_cipher_advance
(
crypto_cipher_env_t
*
env
,
long
delta
);
/* SHA-1 */
int
crypto_digest
(
unsigned
char
*
digest
,
const
unsigned
char
*
m
,
in
t
len
);
int
crypto_digest
(
char
*
digest
,
const
char
*
m
,
size_
t
len
);
crypto_digest_env_t
*
crypto_new_digest_env
(
void
);
void
crypto_free_digest_env
(
crypto_digest_env_t
*
digest
);
void
crypto_digest_add_bytes
(
crypto_digest_env_t
*
digest
,
const
char
*
data
,
...
...
@@ -143,8 +143,8 @@ void crypto_dh_free(crypto_dh_env_t *dh);
/* random numbers */
int
crypto_seed_rng
(
void
);
int
crypto_rand
(
unsigned
char
*
to
,
unsigned
in
t
n
);
void
crypto_pseudo_rand
(
unsigned
char
*
to
,
unsigned
in
t
n
);
int
crypto_rand
(
char
*
to
,
size_
t
n
);
void
crypto_pseudo_rand
(
char
*
to
,
size_
t
n
);
int
crypto_pseudo_rand_int
(
unsigned
int
max
);
struct
smartlist_t
;
...
...
src/common/torgzip.c
View file @
10b2208d
...
...
@@ -94,7 +94,7 @@ tor_gzip_compress(char **out, size_t *out_len,
out_size
=
in_len
/
2
;
if
(
out_size
<
1024
)
out_size
=
1024
;
*
out
=
tor_malloc
(
out_size
);
stream
->
next_out
=
*
out
;
stream
->
next_out
=
(
unsigned
char
*
)
*
out
;
stream
->
avail_out
=
out_size
;
while
(
1
)
{
...
...
@@ -110,7 +110,7 @@ tor_gzip_compress(char **out, size_t *out_len,
offset
=
stream
->
next_out
-
((
unsigned
char
*
)
*
out
);
out_size
*=
2
;
*
out
=
tor_realloc
(
*
out
,
out_size
);
stream
->
next_out
=
*
out
+
offset
;
stream
->
next_out
=
(
unsigned
char
*
)(
*
out
+
offset
)
;
stream
->
avail_out
=
out_size
-
offset
;
break
;
default:
...
...
@@ -179,7 +179,7 @@ tor_gzip_uncompress(char **out, size_t *out_len,
if
(
out_size
<
1024
)
out_size
=
1024
;
*
out
=
tor_malloc
(
out_size
);
stream
->
next_out
=
*
out
;
stream
->
next_out
=
(
unsigned
char
*
)
*
out
;
stream
->
avail_out
=
out_size
;
while
(
1
)
{
...
...
@@ -195,7 +195,7 @@ tor_gzip_uncompress(char **out, size_t *out_len,
offset
=
stream
->
next_out
-
((
unsigned
char
*
)
*
out
);
out_size
*=
2
;
*
out
=
tor_realloc
(
*
out
,
out_size
);
stream
->
next_out
=
*
out
+
offset
;
stream
->
next_out
=
(
unsigned
char
*
)(
*
out
+
offset
)
;
stream
->
avail_out
=
out_size
-
offset
;
break
;
default:
...
...
src/common/tortls.c
View file @
10b2208d
...
...
@@ -221,10 +221,10 @@ tor_tls_create_certificate(crypto_pk_env_t *rsa,
goto
error
;
if
((
nid
=
OBJ_txt2nid
(
"organizationName"
))
==
NID_undef
)
goto
error
;
if
(
!
(
X509_NAME_add_entry_by_NID
(
name
,
nid
,
MBSTRING_ASC
,
(
char
*
)
"TOR"
,
-
1
,
-
1
,
0
)))
goto
error
;
(
unsigned
char
*
)
"TOR"
,
-
1
,
-
1
,
0
)))
goto
error
;
if
((
nid
=
OBJ_txt2nid
(
"commonName"
))
==
NID_undef
)
goto
error
;
if
(
!
(
X509_NAME_add_entry_by_NID
(
name
,
nid
,
MBSTRING_ASC
,
(
char
*
)
cname
,
-
1
,
-
1
,
0
)))
goto
error
;
(
unsigned
char
*
)
cname
,
-
1
,
-
1
,
0
)))
goto
error
;
if
(
!
(
X509_set_subject_name
(
x509
,
name
)))
goto
error
;
...
...
@@ -232,10 +232,10 @@ tor_tls_create_certificate(crypto_pk_env_t *rsa,
goto
error
;
if
((
nid
=
OBJ_txt2nid
(
"organizationName"
))
==
NID_undef
)
goto
error
;
if
(
!
(
X509_NAME_add_entry_by_NID
(
name_issuer
,
nid
,
MBSTRING_ASC
,
(
char
*
)
"TOR"
,
-
1
,
-
1
,
0
)))
goto
error
;
(
unsigned
char
*
)
"TOR"
,
-
1
,
-
1
,
0
)))
goto
error
;
if
((
nid
=
OBJ_txt2nid
(
"commonName"
))
==
NID_undef
)
goto
error
;
if
(
!
(
X509_NAME_add_entry_by_NID
(
name_issuer
,
nid
,
MBSTRING_ASC
,
(
char
*
)
cname_sign
,
-
1
,
-
1
,
0
)))
goto
error
;
(
unsigned
char
*
)
cname_sign
,
-
1
,
-
1
,
0
)))
goto
error
;
if
(
!
(
X509_set_issuer_name
(
x509
,
name_issuer
)))
goto
error
;
...
...
src/or/circuitbuild.c
View file @
10b2208d
...
...
@@ -676,7 +676,7 @@ int circuit_init_cpath_crypto(crypt_path_t *cpath, char *key_data, int reverse)
* Return -1 if we want to mark circ for close, else return 0.
*/
int
circuit_finish_handshake
(
circuit_t
*
circ
,
uint8_t
reply_type
,
char
*
reply
)
{
unsigned
char
keys
[
CPATH_KEY_MATERIAL_LEN
];
char
keys
[
CPATH_KEY_MATERIAL_LEN
];
crypt_path_t
*
hop
;
tor_assert
(
CIRCUIT_IS_ORIGIN
(
circ
));
...
...
@@ -778,7 +778,7 @@ int circuit_truncated(circuit_t *circ, crypt_path_t *layer) {
/** Given a response payload and keys, initialize, then send a created
* cell back.
*/
int
onionskin_answer
(
circuit_t
*
circ
,
uint8_t
cell_type
,
unsigned
char
*
payload
,
unsigned
char
*
keys
)
{
int
onionskin_answer
(
circuit_t
*
circ
,
uint8_t
cell_type
,
char
*
payload
,
char
*
keys
)
{
cell_t
cell
;
crypt_path_t
*
tmp_cpath
;
...
...
src/or/command.c
View file @
10b2208d
...
...
@@ -196,8 +196,8 @@ static void command_process_create_cell(cell_t *cell, connection_t *conn) {
}
log_fn
(
LOG_DEBUG
,
"success: handed off onionskin."
);
}
else
{
unsigned
char
keys
[
CPATH_KEY_MATERIAL_LEN
];
unsigned
char
reply
[
DIGEST_LEN
*
2
];
char
keys
[
CPATH_KEY_MATERIAL_LEN
];
char
reply
[
DIGEST_LEN
*
2
];
tor_assert
(
cell
->
command
==
CELL_CREATE_FAST
);
if
(
fast_server_handshake
(
cell
->
payload
,
reply
,
keys
,
sizeof
(
keys
))
<
0
)
{
log_fn
(
LOG_WARN
,
"Failed to generate key material. Closing."
);
...
...
src/or/connection.c
View file @
10b2208d
...
...
@@ -533,8 +533,8 @@ static int connection_handle_listener_read(connection_t *conn, int new_type) {
/* information about the remote peer when connecting to other routers */
struct
sockaddr_in
remote
;
char
addrbuf
[
256
];
/* length of the remote address. Must be
an int, since
accept() needs
that
. */
in
t
remotelen
=
256
;
/* length of the remote address. Must be
whatever
accept() needs. */
socklen_
t
remotelen
=
256
;
char
tmpbuf
[
INET_NTOA_BUF_LEN
];
tor_assert
((
size_t
)
remotelen
>=
sizeof
(
struct
sockaddr_in
));
memset
(
addrbuf
,
0
,
sizeof
(
addrbuf
));
...
...
@@ -1046,7 +1046,7 @@ static int connection_read_to_buf(connection_t *conn, int *max_to_read) {
bytes_in_buf
=
buf_capacity
(
conn
->
inbuf
)
-
buf_datalen
(
conn
->
inbuf
);
again:
if
(
at_most
>
bytes_in_buf
&&
bytes_in_buf
>=
1024
)
{
if
(
(
size_t
)
at_most
>
bytes_in_buf
&&
bytes_in_buf
>=
1024
)
{
more_to_read
=
at_most
-
bytes_in_buf
;
at_most
=
bytes_in_buf
;
}
else
{
...
...
@@ -1167,7 +1167,8 @@ int connection_outbuf_too_full(connection_t *conn) {