>> +/* right now we only support difficulties up to sizeof(int), as only ffs
>> + * is available on OpenWRT */
>
> OpenSSL bignums (which are used in HIPL anyway) could be an alternative to ffs(), but a poor WRT is probably not gonna handle such a big puzzle anyway... so I'd say your Solution is OK.
Well, I don't think we will have puzzles of difficulty 32 any time soon.
>> +// For unknown reasons, this file does not compile with the following,
>> +// seemingly useless forward declaration
>> +Suite *lib_core_solve(void);
>
> What's the error message?
This was previously fixed in trunk. Changed accordingly.
René
--
Dipl.-Inform. Rene Hummen, Ph.D. Student
Chair of Communication and Distributed Systems
RWTH Aachen University, Germany
tel: +49 241 80 20772
web: http://www.comsys.rwth-aachen.de/team/rene-hummen/
On 07.04.2011, at 21:59, Christof Mroz wrote: puzzle_ solution( const struct puzzle_common *const compute_puzzle, SHA_DIGEST_ LENGTH] , "puzzle" , puzzle_or_solution, "(u->pz. I: 0x%llx\n", u->pz.I); copy((hip_ hit_t *) (cookie + 8), &hdr->hits); copy((hip_ hit_t *) (cookie + 24), &hdr->hitr); copy((hip_ hit_t *) (cookie + 8), &hdr->hitr); copy((hip_ hit_t *) (cookie + 24), &hdr->hits); bytes(& randval, sizeof(uint64_t)); difficulty, hip_build_ digest( HIP_DIGEST_ SHA1,
> Review: Needs Fixing
> Overall, this is definately cleaner than the old code.
>
> There is one piece of code that does not match its corresponding comment; as soon as this is clarified (or fixed), I'll approve.
> Would be nice if you could address the other points too (mainly missing documentation for newly added functions).
>
>> +static int hip_calculate_
>> + unsigned char sha_digest[
>> + const int difficulty)
>> {
>> - uint64_t mask = 0;
>> - uint64_t randval = 0;
>> - uint64_t maxtries = 0;
>> - uint64_t digest = 0;
>> - uint8_t cookie[48];
>> - int err = 0;
>> - const union {
>> - struct hip_puzzle pz;
>> - struct hip_solution sl;
>> - } *u;
>> -
>> - HIP_HEXDUMP(
>> - (mode == HIP_VERIFY_PUZZLE ? sizeof(struct hip_solution) :
>> - sizeof(struct hip_puzzle)));
>> -
>> - /* pre-create cookie */
>> - u = puzzle_or_solution;
>> -
>> - HIP_IFEL(u->pz.K > HIP_PUZZLE_MAX_K, 0,
>> - "Cookie K %u is higher than we are willing to calculate"
>> - " (current max K=%d)\n", u->pz.K, HIP_PUZZLE_MAX_K);
>> -
>> - mask = hton64((1ULL << u->pz.K) - 1);
>> - memcpy(cookie, &u->pz.I, sizeof(uint64_t));
>> -
>> - HIP_DEBUG(
>> -
>> - if (mode == HIP_VERIFY_PUZZLE) {
>> - ipv6_addr_
>> - ipv6_addr_
>> - randval = u->sl.J;
>> - maxtries = 1;
>> - } else if (mode == HIP_SOLVE_PUZZLE) {
>> - ipv6_addr_
>> - ipv6_addr_
>> - maxtries = 1ULL << (u->pz.K + 3);
>> - get_random_
>> + uint32_t truncated_digest = 0;
>> + int err = -1;
>> +
>> + HIP_IFEL(difficulty > max_puzzle_
>> + 1, "difficulty exceeds max. configured difficulty\n");
>> +
>> + HIP_IFEL(
>> + compute_puzzle,
>> + sizeof(struct puzzle_common),
>> + sha_digest),
>> + -1, "failed to compute hash digest\n");
>
> You could return early with a (successful) solution of zero if difficulty == 0.
> If the caller is responsible of taking that shortcut, I'd add an assertion here to catch future callers who forget about this.
Done. I don't see your point in adding an assertion here.
>> + /* we are interested in the 8 least significant bytes */ SHA_DIGEST_ LENGTH - sizeof(uint32_t)]; puzzle( const uint64_t puzzle, SHA_DIGEST_ LENGTH] ; difficulty, -1, difficulty) ;
>> + truncated_digest = *(uint32_t *) &sha_digest[
>
> The 8 least significant bytes have index 0..7. Also, sizeof(uint32_t) is 4, not 8.
>
>> +int hip_solve_
>> + const int difficulty,
>> + const hip_hit_t initiator_hit,
>> + const hip_hit_t responder_hit,
>> + uint64_t *solution)
>> +{
>> + struct puzzle_common compute_puzzle;
>> + unsigned char sha_digest[
>> + int err = -1;
>> + uint64_t i = 0;
>> +
>> + HIP_IFEL(!solution, -1, "invalid parameter passed (NULL)\n");
>> +
>> + HIP_IFEL(difficulty > max_puzzle_
>> + "Cookie (K = %i) is higher than we are willing to calculate"
>> + " (current max K = %i)\n", difficulty, max_puzzle_
>
> Again, we can exit early for difficulty = 0.
Done.
>> +} puzzle_ solution( const uint64_t puzzle,
>> +
>> +int hip_verify_
>> + const uint8_t difficulty,
>> + const hip_hit_t initiator_hit,
>> + const hip_hit_t responder_hit,
>> + const uint64_t solution)
>
> Missing documentation (there are other instances too).
Done. Also for the other instances.
>> +/* right now we only support difficulties up to sizeof(int), as only ffs
>> + * is available on OpenWRT */
>
> OpenSSL bignums (which are used in HIPL anyway) could be an alternative to ffs(), but a poor WRT is probably not gonna handle such a big puzzle anyway... so I'd say your Solution is OK.
Well, I don't think we will have puzzles of difficulty 32 any time soon.
>> +// For unknown reasons, this file does not compile with the following, solve(void) ;
>> +// seemingly useless forward declaration
>> +Suite *lib_core_
>
> What's the error message?
This was previously fixed in trunk. Changed accordingly.
René
-- www.comsys. rwth-aachen. de/team/ rene-hummen/
Dipl.-Inform. Rene Hummen, Ph.D. Student
Chair of Communication and Distributed Systems
RWTH Aachen University, Germany
tel: +49 241 80 20772
web: http://