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
92451f74
Commit
92451f74
authored
Sep 30, 2005
by
Nick Mathewson
🥄
Browse files
Reformat inconsistent function declarations.
svn:r5160
parent
6ce1add8
Changes
20
Hide whitespace changes
Inline
Side-by-side
src/common/aes.c
View file @
92451f74
...
@@ -608,7 +608,9 @@ static const u32 rcon[] = {
...
@@ -608,7 +608,9 @@ static const u32 rcon[] = {
*
*
* @return the number of rounds for the given cipher key size.
* @return the number of rounds for the given cipher key size.
*/
*/
int
rijndaelKeySetupEnc
(
u32
rk
[
/*4*(Nr + 1)*/
],
const
u8
cipherKey
[],
int
keyBits
)
{
int
rijndaelKeySetupEnc
(
u32
rk
[
/*4*(Nr + 1)*/
],
const
u8
cipherKey
[],
int
keyBits
)
{
int
i
=
0
;
int
i
=
0
;
u32
temp
;
u32
temp
;
...
@@ -689,7 +691,9 @@ int rijndaelKeySetupEnc(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBit
...
@@ -689,7 +691,9 @@ int rijndaelKeySetupEnc(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBit
return
0
;
return
0
;
}
}
void
rijndaelEncrypt
(
const
u32
rk
[
/*4*(Nr + 1)*/
],
int
Nr
,
const
u8
pt
[
16
],
u8
ct
[
16
])
{
void
rijndaelEncrypt
(
const
u32
rk
[
/*4*(Nr + 1)*/
],
int
Nr
,
const
u8
pt
[
16
],
u8
ct
[
16
])
{
u32
s0
,
s1
,
s2
,
s3
,
t0
,
t1
,
t2
,
t3
;
u32
s0
,
s1
,
s2
,
s3
,
t0
,
t1
,
t2
,
t3
;
#ifndef FULL_UNROLL
#ifndef FULL_UNROLL
int
r
;
int
r
;
...
...
src/common/compat.c
View file @
92451f74
...
@@ -440,7 +440,8 @@ tor_socketpair(int family, int type, int protocol, int fd[2])
...
@@ -440,7 +440,8 @@ tor_socketpair(int family, int type, int protocol, int fd[2])
* have a low soft limit.) Make sure we set it to at least
* have a low soft limit.) Make sure we set it to at least
* <b>limit</b>. Return a new limit if we can, or -1 if we fail. */
* <b>limit</b>. Return a new limit if we can, or -1 if we fail. */
int
int
set_max_file_descriptors
(
unsigned
long
limit
,
unsigned
long
cap
)
{
set_max_file_descriptors
(
unsigned
long
limit
,
unsigned
long
cap
)
{
#ifndef HAVE_GETRLIMIT
#ifndef HAVE_GETRLIMIT
log_fn
(
LOG_INFO
,
"This platform is missing getrlimit(). Proceeding."
);
log_fn
(
LOG_INFO
,
"This platform is missing getrlimit(). Proceeding."
);
if
(
limit
>
cap
)
{
if
(
limit
>
cap
)
{
...
@@ -488,7 +489,8 @@ set_max_file_descriptors(unsigned long limit, unsigned long cap) {
...
@@ -488,7 +489,8 @@ set_max_file_descriptors(unsigned long limit, unsigned long cap) {
* success. On failure, log and return -1.
* success. On failure, log and return -1.
*/
*/
int
int
switch_id
(
char
*
user
,
char
*
group
)
{
switch_id
(
char
*
user
,
char
*
group
)
{
#ifndef MS_WINDOWS
#ifndef MS_WINDOWS
struct
passwd
*
pw
=
NULL
;
struct
passwd
*
pw
=
NULL
;
struct
group
*
gr
=
NULL
;
struct
group
*
gr
=
NULL
;
...
@@ -1041,7 +1043,8 @@ struct tor_mutex_t {
...
@@ -1041,7 +1043,8 @@ struct tor_mutex_t {
* socket to get the error.
* socket to get the error.
*/
*/
#ifdef MS_WINDOWS
#ifdef MS_WINDOWS
int
tor_socket_errno
(
int
sock
)
int
tor_socket_errno
(
int
sock
)
{
{
int
optval
,
optvallen
=
sizeof
(
optval
);
int
optval
,
optvallen
=
sizeof
(
optval
);
int
err
=
WSAGetLastError
();
int
err
=
WSAGetLastError
();
...
...
src/common/container.c
View file @
92451f74
...
@@ -43,7 +43,8 @@ struct smartlist_t {
...
@@ -43,7 +43,8 @@ struct smartlist_t {
/** Allocate and return an empty smartlist.
/** Allocate and return an empty smartlist.
*/
*/
smartlist_t
*
smartlist_t
*
smartlist_create
(
void
)
{
smartlist_create
(
void
)
{
smartlist_t
*
sl
=
tor_malloc
(
sizeof
(
smartlist_t
));
smartlist_t
*
sl
=
tor_malloc
(
sizeof
(
smartlist_t
));
sl
->
num_used
=
0
;
sl
->
num_used
=
0
;
sl
->
capacity
=
SMARTLIST_DEFAULT_CAPACITY
;
sl
->
capacity
=
SMARTLIST_DEFAULT_CAPACITY
;
...
@@ -55,7 +56,8 @@ smartlist_create(void) {
...
@@ -55,7 +56,8 @@ smartlist_create(void) {
* list's elements.
* list's elements.
*/
*/
void
void
smartlist_free
(
smartlist_t
*
sl
)
{
smartlist_free
(
smartlist_t
*
sl
)
{
free
(
sl
->
list
);
free
(
sl
->
list
);
free
(
sl
);
free
(
sl
);
}
}
...
@@ -66,7 +68,9 @@ smartlist_free(smartlist_t *sl) {
...
@@ -66,7 +68,9 @@ smartlist_free(smartlist_t *sl) {
* currently in the list, reduce the list's capacity as much as
* currently in the list, reduce the list's capacity as much as
* possible without losing elements.
* possible without losing elements.
*/
*/
void
smartlist_set_capacity
(
smartlist_t
*
sl
,
int
n
)
{
void
smartlist_set_capacity
(
smartlist_t
*
sl
,
int
n
)
{
if
(
n
<
sl
->
num_used
)
if
(
n
<
sl
->
num_used
)
n
=
sl
->
num_used
;
n
=
sl
->
num_used
;
if
(
sl
->
capacity
!=
n
)
{
if
(
sl
->
capacity
!=
n
)
{
...
@@ -78,7 +82,8 @@ void smartlist_set_capacity(smartlist_t *sl, int n) {
...
@@ -78,7 +82,8 @@ void smartlist_set_capacity(smartlist_t *sl, int n) {
/** Remove all elements from the list.
/** Remove all elements from the list.
*/
*/
void
void
smartlist_clear
(
smartlist_t
*
sl
)
{
smartlist_clear
(
smartlist_t
*
sl
)
{
sl
->
num_used
=
0
;
sl
->
num_used
=
0
;
}
}
...
@@ -95,7 +100,8 @@ smartlist_truncate(smartlist_t *sl, int len)
...
@@ -95,7 +100,8 @@ smartlist_truncate(smartlist_t *sl, int len)
/** Append element to the end of the list. */
/** Append element to the end of the list. */
void
void
smartlist_add
(
smartlist_t
*
sl
,
void
*
element
)
{
smartlist_add
(
smartlist_t
*
sl
,
void
*
element
)
{
if
(
sl
->
num_used
>=
sl
->
capacity
)
{
if
(
sl
->
num_used
>=
sl
->
capacity
)
{
int
higher
=
sl
->
capacity
*
2
;
int
higher
=
sl
->
capacity
*
2
;
tor_assert
(
higher
>
sl
->
capacity
);
/* detect overflow */
tor_assert
(
higher
>
sl
->
capacity
);
/* detect overflow */
...
...
src/common/crypto.c
View file @
92451f74
...
@@ -119,7 +119,8 @@ static int tor_check_dh_key(BIGNUM *bn);
...
@@ -119,7 +119,8 @@ static int tor_check_dh_key(BIGNUM *bn);
/** Return the number of bytes added by padding method <b>padding</b>.
/** Return the number of bytes added by padding method <b>padding</b>.
*/
*/
static
INLINE
int
static
INLINE
int
crypto_get_rsa_padding_overhead
(
int
padding
)
{
crypto_get_rsa_padding_overhead
(
int
padding
)
{
switch
(
padding
)
switch
(
padding
)
{
{
case
RSA_NO_PADDING
:
return
0
;
case
RSA_NO_PADDING
:
return
0
;
...
@@ -132,7 +133,8 @@ crypto_get_rsa_padding_overhead(int padding) {
...
@@ -132,7 +133,8 @@ crypto_get_rsa_padding_overhead(int padding) {
/** Given a padding method <b>padding</b>, return the correct OpenSSL constant.
/** Given a padding method <b>padding</b>, return the correct OpenSSL constant.
*/
*/
static
INLINE
int
static
INLINE
int
crypto_get_rsa_padding
(
int
padding
)
{
crypto_get_rsa_padding
(
int
padding
)
{
switch
(
padding
)
switch
(
padding
)
{
{
case
PK_NO_PADDING
:
return
RSA_NO_PADDING
;
case
PK_NO_PADDING
:
return
RSA_NO_PADDING
;
...
@@ -216,7 +218,8 @@ crypto_global_init(int useAccel)
...
@@ -216,7 +218,8 @@ crypto_global_init(int useAccel)
/** Uninitialize the crypto library. Return 0 on success, -1 on failure.
/** Uninitialize the crypto library. Return 0 on success, -1 on failure.
*/
*/
int
crypto_global_cleanup
(
void
)
int
crypto_global_cleanup
(
void
)
{
{
ERR_free_strings
();
ERR_free_strings
();
#ifndef NO_ENGINES
#ifndef NO_ENGINES
...
@@ -304,7 +307,8 @@ crypto_pk_env_t *crypto_new_pk_env(void)
...
@@ -304,7 +307,8 @@ crypto_pk_env_t *crypto_new_pk_env(void)
/** Release a reference to an asymmetric key; when all the references
/** Release a reference to an asymmetric key; when all the references
* are released, free the key.
* are released, free the key.
*/
*/
void
crypto_free_pk_env
(
crypto_pk_env_t
*
env
)
void
crypto_free_pk_env
(
crypto_pk_env_t
*
env
)
{
{
tor_assert
(
env
);
tor_assert
(
env
);
...
@@ -365,7 +369,8 @@ crypto_cipher_env_t *crypto_new_cipher_env(void)
...
@@ -365,7 +369,8 @@ crypto_cipher_env_t *crypto_new_cipher_env(void)
/** Free a symmetric cipher.
/** Free a symmetric cipher.
*/
*/
void
crypto_free_cipher_env
(
crypto_cipher_env_t
*
env
)
void
crypto_free_cipher_env
(
crypto_cipher_env_t
*
env
)
{
{
tor_assert
(
env
);
tor_assert
(
env
);
...
@@ -379,7 +384,8 @@ void crypto_free_cipher_env(crypto_cipher_env_t *env)
...
@@ -379,7 +384,8 @@ void crypto_free_cipher_env(crypto_cipher_env_t *env)
/** Generate a new public/private keypair in <b>env</b>. Return 0 on
/** Generate a new public/private keypair in <b>env</b>. Return 0 on
* success, -1 on failure.
* success, -1 on failure.
*/
*/
int
crypto_pk_generate_key
(
crypto_pk_env_t
*
env
)
int
crypto_pk_generate_key
(
crypto_pk_env_t
*
env
)
{
{
tor_assert
(
env
);
tor_assert
(
env
);
...
@@ -397,8 +403,9 @@ int crypto_pk_generate_key(crypto_pk_env_t *env)
...
@@ -397,8 +403,9 @@ int crypto_pk_generate_key(crypto_pk_env_t *env)
/** Read a PEM-encoded private key from the string <b>s</b> into <b>env</b>.
/** Read a PEM-encoded private key from the string <b>s</b> into <b>env</b>.
* Return 0 on success, -1 on failure.
* Return 0 on success, -1 on failure.
*/
*/
static
int
crypto_pk_read_private_key_from_string
(
crypto_pk_env_t
*
env
,
static
int
const
char
*
s
)
crypto_pk_read_private_key_from_string
(
crypto_pk_env_t
*
env
,
const
char
*
s
)
{
{
BIO
*
b
;
BIO
*
b
;
...
@@ -425,7 +432,8 @@ static int crypto_pk_read_private_key_from_string(crypto_pk_env_t *env,
...
@@ -425,7 +432,8 @@ static int crypto_pk_read_private_key_from_string(crypto_pk_env_t *env,
/** Read a PEM-encoded private key from the file named by
/** Read a PEM-encoded private key from the file named by
* <b>keyfile</b> into <b>env</b>. Return 0 on success, -1 on failure.
* <b>keyfile</b> into <b>env</b>. Return 0 on success, -1 on failure.
*/
*/
int
crypto_pk_read_private_key_from_filename
(
crypto_pk_env_t
*
env
,
const
char
*
keyfile
)
int
crypto_pk_read_private_key_from_filename
(
crypto_pk_env_t
*
env
,
const
char
*
keyfile
)
{
{
char
*
contents
;
char
*
contents
;
int
r
;
int
r
;
...
@@ -455,7 +463,9 @@ int crypto_pk_read_private_key_from_filename(crypto_pk_env_t *env, const char *k
...
@@ -455,7 +463,9 @@ int crypto_pk_read_private_key_from_filename(crypto_pk_env_t *env, const char *k
* string, *<b>len</b> to the string's length, and return 0. On
* string, *<b>len</b> to the string's length, and return 0. On
* failure, return -1.
* failure, return -1.
*/
*/
int
crypto_pk_write_public_key_to_string
(
crypto_pk_env_t
*
env
,
char
**
dest
,
size_t
*
len
)
{
int
crypto_pk_write_public_key_to_string
(
crypto_pk_env_t
*
env
,
char
**
dest
,
size_t
*
len
)
{
BUF_MEM
*
buf
;
BUF_MEM
*
buf
;
BIO
*
b
;
BIO
*
b
;
...
@@ -491,7 +501,9 @@ int crypto_pk_write_public_key_to_string(crypto_pk_env_t *env, char **dest, size
...
@@ -491,7 +501,9 @@ int crypto_pk_write_public_key_to_string(crypto_pk_env_t *env, char **dest, size
* <b>src</b>, and store the result in <b>env</b>. Return 0 on success, -1 on
* <b>src</b>, and store the result in <b>env</b>. Return 0 on success, -1 on
* failure.
* failure.
*/
*/
int
crypto_pk_read_public_key_from_string
(
crypto_pk_env_t
*
env
,
const
char
*
src
,
size_t
len
)
{
int
crypto_pk_read_public_key_from_string
(
crypto_pk_env_t
*
env
,
const
char
*
src
,
size_t
len
)
{
BIO
*
b
;
BIO
*
b
;
tor_assert
(
env
);
tor_assert
(
env
);
...
@@ -556,7 +568,8 @@ crypto_pk_write_private_key_to_filename(crypto_pk_env_t *env,
...
@@ -556,7 +568,8 @@ crypto_pk_write_private_key_to_filename(crypto_pk_env_t *env,
* directories containing "opt keyword\n-----BEGIN OBJECT----" entries
* directories containing "opt keyword\n-----BEGIN OBJECT----" entries
* in versions of Tor up to 0.0.9pre2.</i>
* in versions of Tor up to 0.0.9pre2.</i>
*/
*/
int
crypto_pk_DER64_encode_public_key
(
crypto_pk_env_t
*
env
,
char
**
out
)
int
crypto_pk_DER64_encode_public_key
(
crypto_pk_env_t
*
env
,
char
**
out
)
{
{
int
len
;
int
len
;
char
buf
[
PK_BYTES
*
2
];
/* Too long, but hey, stacks are big. */
char
buf
[
PK_BYTES
*
2
];
/* Too long, but hey, stacks are big. */
...
@@ -585,7 +598,8 @@ int crypto_pk_DER64_encode_public_key(crypto_pk_env_t *env, char **out)
...
@@ -585,7 +598,8 @@ int crypto_pk_DER64_encode_public_key(crypto_pk_env_t *env, char **out)
* directories containing "opt keyword\n-----BEGIN OBJECT----" entries
* directories containing "opt keyword\n-----BEGIN OBJECT----" entries
* in versions of Tor up to 0.0.9pre2.</i>
* in versions of Tor up to 0.0.9pre2.</i>
*/
*/
crypto_pk_env_t
*
crypto_pk_DER64_decode_public_key
(
const
char
*
in
)
crypto_pk_env_t
*
crypto_pk_DER64_decode_public_key
(
const
char
*
in
)
{
{
char
partitioned
[
PK_BYTES
*
2
+
16
];
char
partitioned
[
PK_BYTES
*
2
+
16
];
char
buf
[
PK_BYTES
*
2
];
char
buf
[
PK_BYTES
*
2
];
...
@@ -611,7 +625,8 @@ crypto_pk_env_t *crypto_pk_DER64_decode_public_key(const char *in)
...
@@ -611,7 +625,8 @@ crypto_pk_env_t *crypto_pk_DER64_decode_public_key(const char *in)
/** Return true iff <b>env</b> has a valid key.
/** Return true iff <b>env</b> has a valid key.
*/
*/
int
crypto_pk_check_key
(
crypto_pk_env_t
*
env
)
int
crypto_pk_check_key
(
crypto_pk_env_t
*
env
)
{
{
int
r
;
int
r
;
tor_assert
(
env
);
tor_assert
(
env
);
...
@@ -625,7 +640,9 @@ int crypto_pk_check_key(crypto_pk_env_t *env)
...
@@ -625,7 +640,9 @@ int crypto_pk_check_key(crypto_pk_env_t *env)
/** Compare the public-key components of a and b. Return -1 if a\<b, 0
/** Compare the public-key components of a and b. Return -1 if a\<b, 0
* if a==b, and 1 if a\>b.
* if a==b, and 1 if a\>b.
*/
*/
int
crypto_pk_cmp_keys
(
crypto_pk_env_t
*
a
,
crypto_pk_env_t
*
b
)
{
int
crypto_pk_cmp_keys
(
crypto_pk_env_t
*
a
,
crypto_pk_env_t
*
b
)
{
int
result
;
int
result
;
if
(
!
a
||
!
b
)
if
(
!
a
||
!
b
)
...
@@ -643,7 +660,8 @@ int crypto_pk_cmp_keys(crypto_pk_env_t *a, crypto_pk_env_t *b) {
...
@@ -643,7 +660,8 @@ 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. */
/** Return the size of the public key modulus in <b>env</b>, in bytes. */
size_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
);
tor_assert
(
env
->
key
);
tor_assert
(
env
->
key
);
...
@@ -653,7 +671,9 @@ size_t crypto_pk_keysize(crypto_pk_env_t *env)
...
@@ -653,7 +671,9 @@ size_t crypto_pk_keysize(crypto_pk_env_t *env)
/** Increase the reference count of <b>env</b>, and return it.
/** Increase the reference count of <b>env</b>, and return it.
*/
*/
crypto_pk_env_t
*
crypto_pk_dup_key
(
crypto_pk_env_t
*
env
)
{
crypto_pk_env_t
*
crypto_pk_dup_key
(
crypto_pk_env_t
*
env
)
{
tor_assert
(
env
);
tor_assert
(
env
);
tor_assert
(
env
->
key
);
tor_assert
(
env
->
key
);
...
@@ -827,11 +847,12 @@ crypto_pk_private_sign_digest(crypto_pk_env_t *env, char *to,
...
@@ -827,11 +847,12 @@ crypto_pk_private_sign_digest(crypto_pk_env_t *env, char *to,
* padded and encrypted with the public key; followed by the rest of
* padded and encrypted with the public key; followed by the rest of
* the source data encrypted in AES-CTR mode with the symmetric key.
* the source data encrypted in AES-CTR mode with the symmetric key.
*/
*/
int
crypto_pk_public_hybrid_encrypt
(
crypto_pk_env_t
*
env
,
int
char
*
to
,
crypto_pk_public_hybrid_encrypt
(
crypto_pk_env_t
*
env
,
const
char
*
from
,
char
*
to
,
size_t
fromlen
,
const
char
*
from
,
int
padding
,
int
force
)
size_t
fromlen
,
int
padding
,
int
force
)
{
{
int
overhead
,
outlen
,
r
,
symlen
;
int
overhead
,
outlen
,
r
,
symlen
;
size_t
pkeylen
;
size_t
pkeylen
;
...
@@ -890,11 +911,12 @@ int crypto_pk_public_hybrid_encrypt(crypto_pk_env_t *env,
...
@@ -890,11 +911,12 @@ int crypto_pk_public_hybrid_encrypt(crypto_pk_env_t *env,
}
}
/** Invert crypto_pk_public_hybrid_encrypt. */
/** Invert crypto_pk_public_hybrid_encrypt. */
int
crypto_pk_private_hybrid_decrypt
(
crypto_pk_env_t
*
env
,
int
char
*
to
,
crypto_pk_private_hybrid_decrypt
(
crypto_pk_env_t
*
env
,
const
char
*
from
,
char
*
to
,
size_t
fromlen
,
const
char
*
from
,
int
padding
,
int
warnOnFailure
)
size_t
fromlen
,
int
padding
,
int
warnOnFailure
)
{
{
int
overhead
,
outlen
,
r
;
int
overhead
,
outlen
,
r
;
size_t
pkeylen
;
size_t
pkeylen
;
...
@@ -937,7 +959,8 @@ int crypto_pk_private_hybrid_decrypt(crypto_pk_env_t *env,
...
@@ -937,7 +959,8 @@ int crypto_pk_private_hybrid_decrypt(crypto_pk_env_t *env,
/** ASN.1-encode the public portion of <b>pk</b> into <b>dest</b>.
/** ASN.1-encode the public portion of <b>pk</b> into <b>dest</b>.
* Return -1 on error, or the number of characters used on success.
* Return -1 on error, or the number of characters used on success.
*/
*/
int
crypto_pk_asn1_encode
(
crypto_pk_env_t
*
pk
,
char
*
dest
,
int
dest_len
)
int
crypto_pk_asn1_encode
(
crypto_pk_env_t
*
pk
,
char
*
dest
,
int
dest_len
)
{
{
int
len
;
int
len
;
unsigned
char
*
buf
,
*
cp
;
unsigned
char
*
buf
,
*
cp
;
...
@@ -962,7 +985,8 @@ int crypto_pk_asn1_encode(crypto_pk_env_t *pk, char *dest, int dest_len)
...
@@ -962,7 +985,8 @@ 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
/** Decode an ASN.1-encoded public key from <b>str</b>; return the result on
* success and NULL on failure.
* success and NULL on failure.
*/
*/
crypto_pk_env_t
*
crypto_pk_asn1_decode
(
const
char
*
str
,
size_t
len
)
crypto_pk_env_t
*
crypto_pk_asn1_decode
(
const
char
*
str
,
size_t
len
)
{
{
RSA
*
rsa
;
RSA
*
rsa
;
unsigned
char
*
buf
;
unsigned
char
*
buf
;
...
@@ -989,7 +1013,8 @@ crypto_pk_env_t *crypto_pk_asn1_decode(const char *str, size_t len)
...
@@ -989,7 +1013,8 @@ crypto_pk_env_t *crypto_pk_asn1_decode(const char *str, size_t len)
* public key into <b>digest_out</b> (must have DIGEST_LEN bytes of space).
* public key into <b>digest_out</b> (must have DIGEST_LEN bytes of space).
* Return 0 on success, -1 on failure.
* Return 0 on success, -1 on failure.
*/
*/
int
crypto_pk_get_digest
(
crypto_pk_env_t
*
pk
,
char
*
digest_out
)
int
crypto_pk_get_digest
(
crypto_pk_env_t
*
pk
,
char
*
digest_out
)
{
{
unsigned
char
*
buf
,
*
bufp
;
unsigned
char
*
buf
,
*
bufp
;
int
len
;
int
len
;
...
@@ -1063,7 +1088,8 @@ crypto_pk_check_fingerprint_syntax(const char *s)
...
@@ -1063,7 +1088,8 @@ crypto_pk_check_fingerprint_syntax(const char *s)
/** Generate a new random key for the symmetric cipher in <b>env</b>.
/** Generate a new random key for the symmetric cipher in <b>env</b>.
* Return 0 on success, -1 on failure. Does not initialize the cipher.
* Return 0 on success, -1 on failure. Does not initialize the cipher.
*/
*/
int
crypto_cipher_generate_key
(
crypto_cipher_env_t
*
env
)
int
crypto_cipher_generate_key
(
crypto_cipher_env_t
*
env
)
{
{
tor_assert
(
env
);
tor_assert
(
env
);
...
@@ -1074,7 +1100,8 @@ int crypto_cipher_generate_key(crypto_cipher_env_t *env)
...
@@ -1074,7 +1100,8 @@ int crypto_cipher_generate_key(crypto_cipher_env_t *env)
* CIPHER_KEY_LEN bytes of <b>key</b>. Does not initialize the cipher.
* CIPHER_KEY_LEN bytes of <b>key</b>. Does not initialize the cipher.
* Return 0 on success, -1 on failure.
* Return 0 on success, -1 on failure.
*/
*/
int
crypto_cipher_set_key
(
crypto_cipher_env_t
*
env
,
const
char
*
key
)
int
crypto_cipher_set_key
(
crypto_cipher_env_t
*
env
,
const
char
*
key
)
{
{
tor_assert
(
env
);
tor_assert
(
env
);
tor_assert
(
key
);
tor_assert
(
key
);
...
@@ -1089,7 +1116,8 @@ int crypto_cipher_set_key(crypto_cipher_env_t *env, const char *key)
...
@@ -1089,7 +1116,8 @@ int crypto_cipher_set_key(crypto_cipher_env_t *env, const char *key)
/** Return a pointer to the key set for the cipher in <b>env</b>.
/** Return a pointer to the key set for the cipher in <b>env</b>.
*/
*/
const
char
*
crypto_cipher_get_key
(
crypto_cipher_env_t
*
env
)
const
char
*
crypto_cipher_get_key
(
crypto_cipher_env_t
*
env
)
{
{
return
env
->
key
;
return
env
->
key
;
}
}
...
@@ -1097,7 +1125,8 @@ const char *crypto_cipher_get_key(crypto_cipher_env_t *env)
...
@@ -1097,7 +1125,8 @@ const char *crypto_cipher_get_key(crypto_cipher_env_t *env)
/** Initialize the cipher in <b>env</b> for encryption. Return 0 on
/** Initialize the cipher in <b>env</b> for encryption. Return 0 on
* success, -1 on failure.
* success, -1 on failure.
*/
*/
int
crypto_cipher_encrypt_init_cipher
(
crypto_cipher_env_t
*
env
)
int
crypto_cipher_encrypt_init_cipher
(
crypto_cipher_env_t
*
env
)
{
{
tor_assert
(
env
);
tor_assert
(
env
);
...
@@ -1108,7 +1137,8 @@ int crypto_cipher_encrypt_init_cipher(crypto_cipher_env_t *env)
...
@@ -1108,7 +1137,8 @@ int crypto_cipher_encrypt_init_cipher(crypto_cipher_env_t *env)
/** Initialize the cipher in <b>env</b> for decryption. Return 0 on
/** Initialize the cipher in <b>env</b> for decryption. Return 0 on
* success, -1 on failure.
* success, -1 on failure.
*/
*/
int
crypto_cipher_decrypt_init_cipher
(
crypto_cipher_env_t
*
env
)
int
crypto_cipher_decrypt_init_cipher
(
crypto_cipher_env_t
*
env
)
{
{
tor_assert
(
env
);
tor_assert
(
env
);
...
@@ -1175,7 +1205,8 @@ crypto_cipher_advance(crypto_cipher_env_t *env, long delta)
...
@@ -1175,7 +1205,8 @@ crypto_cipher_advance(crypto_cipher_env_t *env, long delta)
* <b>m</b>. Write the DIGEST_LEN byte result into <b>digest</b>.
* <b>m</b>. Write the DIGEST_LEN byte result into <b>digest</b>.
* Return 0 on success, -1 on failure.
* Return 0 on success, -1 on failure.
*/
*/
int
crypto_digest
(
char
*
digest
,
const
char
*
m
,
size_t
len
)
int
crypto_digest
(
char
*
digest
,
const
char
*
m
,
size_t
len
)
{
{
tor_assert
(
m
);
tor_assert
(
m
);
tor_assert
(
digest
);
tor_assert
(
digest
);
...
@@ -1200,7 +1231,8 @@ crypto_new_digest_env(void)
...
@@ -1200,7 +1231,8 @@ crypto_new_digest_env(void)
/** Deallocate a digest object.
/** Deallocate a digest object.
*/
*/
void
void
crypto_free_digest_env
(
crypto_digest_env_t
*
digest
)
{
crypto_free_digest_env
(
crypto_digest_env_t
*
digest
)
{
tor_free
(
digest
);
tor_free
(
digest
);
}
}
...
@@ -1224,8 +1256,9 @@ crypto_digest_add_bytes(crypto_digest_env_t *digest, const char *data,
...
@@ -1224,8 +1256,9 @@ crypto_digest_add_bytes(crypto_digest_env_t *digest, const char *data,
* object; write the first out_len bytes of the result to <b>out</b>.
* object; write the first out_len bytes of the result to <b>out</b>.
* <b>out_len</b> must be \<= DIGEST_LEN.
* <b>out_len</b> must be \<= DIGEST_LEN.
*/
*/
void
crypto_digest_get_digest
(
crypto_digest_env_t
*
digest
,
void
char
*
out
,
size_t
out_len
)
crypto_digest_get_digest
(
crypto_digest_env_t
*
digest
,
char
*
out
,
size_t
out_len
)
{
{
static
unsigned
char
r
[
DIGEST_LEN
];
static
unsigned
char
r
[
DIGEST_LEN
];
SHA_CTX
tmpctx
;
SHA_CTX
tmpctx
;
...
@@ -1272,7 +1305,9 @@ static BIGNUM *dh_param_g = NULL;
...
@@ -1272,7 +1305,9 @@ static BIGNUM *dh_param_g = NULL;
/** Initialize dh_param_p and dh_param_g if they are not already
/** Initialize dh_param_p and dh_param_g if they are not already
* set. */
* set. */
static
void
init_dh_param
(
void
)
{
static
void
init_dh_param
(
void
)
{
BIGNUM
*
p
,
*
g
;
BIGNUM
*
p
,
*
g
;
int
r
;
int
r
;
if
(
dh_param_p
&&
dh_param_g
)
if
(
dh_param_p
&&
dh_param_g
)
...
@@ -1303,7 +1338,8 @@ static void init_dh_param(void) {
...
@@ -1303,7 +1338,8 @@ static void init_dh_param(void) {
/** Allocate and return a new DH object for a key exchange.
/** Allocate and return a new DH object for a key exchange.
*/
*/
crypto_dh_env_t
*
crypto_dh_new
(
void
)
crypto_dh_env_t
*
crypto_dh_new
(
void
)
{
{
crypto_dh_env_t
*
res
=
NULL
;
crypto_dh_env_t
*
res
=
NULL
;
...
@@ -1331,7 +1367,8 @@ crypto_dh_env_t *crypto_dh_new(void)
...
@@ -1331,7 +1367,8 @@ crypto_dh_env_t *crypto_dh_new(void)
/** Return the length of the DH key in <b>dh</b>, in bytes.
/** Return the length of the DH key in <b>dh</b>, in bytes.
*/
*/
int
crypto_dh_get_bytes
(
crypto_dh_env_t
*
dh
)
int
crypto_dh_get_bytes
(
crypto_dh_env_t
*
dh
)
{
{
tor_assert
(
dh
);
tor_assert
(
dh
);
return
DH_size
(
dh
->
dh
);
return
DH_size
(
dh
->
dh
);
...
@@ -1340,7 +1377,8 @@ int crypto_dh_get_bytes(crypto_dh_env_t *dh)
...
@@ -1340,7 +1377,8 @@ int crypto_dh_get_bytes(crypto_dh_env_t *dh)
/** Generate \<x,g^x\> for our part of the key exchange. Return 0 on
/** Generate \<x,g^x\> for our part of the key exchange. Return 0 on
* success, -1 on failure.
* success, -1 on failure.
*/
*/
int
crypto_dh_generate_public
(
crypto_dh_env_t
*
dh
)
int
crypto_dh_generate_public
(
crypto_dh_env_t
*
dh
)
{
{
again:
again:
if
(
!
DH_generate_key
(
dh
->
dh
))
{
if
(
!
DH_generate_key
(
dh
->
dh
))
{
...
@@ -1362,7 +1400,8 @@ int crypto_dh_generate_public(crypto_dh_env_t *dh)
...
@@ -1362,7 +1400,8 @@ int crypto_dh_generate_public(crypto_dh_env_t *dh)
* as a <b>pubkey_len</b>-byte value into <b>pubkey</b>. Return 0 on
* as a <b>pubkey_len</b>-byte value into <b>pubkey</b>. Return 0 on