[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-bugs] #17796 [Tor]: Make crypto_digest_t allocated using minimal memory
#17796: Make crypto_digest_t allocated using minimal memory
------------------------+--------------------------------
Reporter: nickm | Owner:
Type: defect | Status: new
Priority: Medium | Milestone: Tor: 0.2.8.x-final
Component: Tor | Version:
Severity: Normal | Keywords:
Actual Points: | Parent ID:
Points: | Sponsor:
------------------------+--------------------------------
We will soon have:
{{{
struct crypto_digest_t {
union {
SHA_CTX sha1;
SHA256_CTX sha2;
SHA512_CTX sha512; // added in 0.2.8
keccak_state sha3; // added by #17783
} d;
digest_algorithm_bitfield_t algorithm : 8;
};
}}}
On my 64-bit host:
{{{
Size of SHA_CTX == 96
Size of SHA256_CTX == 112
Size of SHA512_CTX == 216
Size of keccak_state == 432
}}}
This means that when we allocate a sha1 digest object in order to compute
the running SHA1 of an input stream (for the current tor relay protocol),
we have been wasting 16 bytes, we are now wasting 120 bytes, and we will
soon be wasting 336 bytes.
We should probably adjust the way we lay out and allocate the
crypto_digest_t structure so that it looks more like this:
{{{
struct crypto_digest_t {
digest_algorithm_t algorithm; // no point in a bitfield
union {
SHA_CTX sha1;
SHA256_CTX sha2;
SHA512_CTX sha512; // added in 0.2.8
keccak_state sha3; // added by #17783
} d;
}}}
and we should have crypto_digest*_new allocate no more bytes than the
algorithm will actually use.
--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/17796>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online
_______________________________________________
tor-bugs mailing list
tor-bugs@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-bugs