Skip to content

Commit

Permalink
generate all init round numbers in the begining
Browse files Browse the repository at this point in the history
  • Loading branch information
arun committed Nov 13, 2019
1 parent e3e2a59 commit e1f1890
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 37 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2018 P. Arun Babu <[email protected]> and
Copyright (c) 2019 P. Arun Babu <[email protected]> and
Jithin Jose Thomas <[email protected]>

Permission to use, copy, modify, and distribute this software for any
Expand Down
2 changes: 1 addition & 1 deletion freestyle.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 P. Arun Babu and Jithin Jose Thomas
* Copyright (c) 2019 P. Arun Babu and Jithin Jose Thomas
* arun DOT hbni AT gmail DOT com, jithinjosethomas AT gmail DOT com
*
* Permission to use, copy, modify, and distribute this software for any
Expand Down
2 changes: 1 addition & 1 deletion freestyle.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 P. Arun Babu and Jithin Jose Thomas
* Copyright (c) 2019 P. Arun Babu and Jithin Jose Thomas
* arun DOT hbni AT gmail DOT com, jithinjosethomas AT gmail DOT com
*
* Permission to use, copy, modify, and distribute this software for any
Expand Down
21 changes: 14 additions & 7 deletions optimized/8-32/freestyle.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 P. Arun Babu and Jithin Jose Thomas
* Copyright (c) 2019 P. Arun Babu and Jithin Jose Thomas
* arun DOT hbni AT gmail DOT com, jithinjosethomas AT gmail DOT com
*
* Permission to use, copy, modify, and distribute this software for any
Expand Down Expand Up @@ -123,14 +123,14 @@ static void freestyle_roundsetup (

static u8 freestyle_encrypt_block (
freestyle_ctx *x,
const u8 rounds,
u8 *expected_hash)
{
u8 hash = 0;

u32 temp1, temp2;

u8 r;
u8 rounds;

u32 hash_collided [8];

Expand All @@ -156,9 +156,6 @@ static u8 freestyle_encrypt_block (

memset (hash_collided, 0, sizeof(hash_collided));

/* Generate a random round */
freestyle_random_round_number(x,rounds);

for (r = x->num_precomputed_rounds + 1; r <= rounds; ++r)
{
if (r & 1)
Expand Down Expand Up @@ -286,7 +283,16 @@ static void freestyle_randomsetup_encrypt (freestyle_ctx *x)
x->num_precomputed_rounds = 4;

for (i = 0; i < MAX_INIT_HASHES; ++i) {
R [i] = CR[i] = 0;

R[i] = CR[i] = 0;

// generate all init random round numbers
if (i < x->num_init_hashes)
{
R[i] = x->min_rounds + arc4random_uniform(
x->max_rounds - x->min_rounds + 1
);
}
}

/* initial pre-computed rounds */
Expand All @@ -297,8 +303,9 @@ static void freestyle_randomsetup_encrypt (freestyle_ctx *x)

for (i = 0; i < x->num_init_hashes; ++i)
{
R[i] = freestyle_encrypt_block (
freestyle_encrypt_block (
x,
R[i],
&x->init_hash [i]
);

Expand Down
2 changes: 1 addition & 1 deletion optimized/merged/freestyle-opt.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 P. Arun Babu and Jithin Jose Thomas
* Copyright (c) 2019 P. Arun Babu and Jithin Jose Thomas
* arun DOT hbni AT gmail DOT com, jithinjosethomas AT gmail DOT com
*
* Permission to use, copy, modify, and distribute this software for any
Expand Down
21 changes: 14 additions & 7 deletions optimized/merged/freestyle.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 P. Arun Babu and Jithin Jose Thomas
* Copyright (c) 2019 P. Arun Babu and Jithin Jose Thomas
* arun DOT hbni AT gmail DOT com, jithinjosethomas AT gmail DOT com
*
* Permission to use, copy, modify, and distribute this software for any
Expand Down Expand Up @@ -123,14 +123,14 @@ static void freestyle_roundsetup (

static u8 freestyle_encrypt_block (
freestyle_ctx *x,
const u8 rounds,
u8 *expected_hash)
{
u8 hash = 0;

u32 temp1, temp2;

u8 r;
u8 rounds;

u32 hash_collided [8];

Expand All @@ -156,9 +156,6 @@ static u8 freestyle_encrypt_block (

memset (hash_collided, 0, sizeof(hash_collided));

/* Generate a random round */
freestyle_random_round_number(x,rounds);

for (r = x->num_precomputed_rounds + 1; r <= rounds; ++r)
{
if (r & 1)
Expand Down Expand Up @@ -286,7 +283,16 @@ static void freestyle_randomsetup_encrypt (freestyle_ctx *x)
x->num_precomputed_rounds = 4;

for (i = 0; i < MAX_INIT_HASHES; ++i) {
R [i] = CR[i] = 0;

R[i] = CR[i] = 0;

// generate all init random round numbers
if (i < x->num_init_hashes)
{
R[i] = x->min_rounds + arc4random_uniform(
x->max_rounds - x->min_rounds + 1
);
}
}

/* initial pre-computed rounds */
Expand All @@ -297,8 +303,9 @@ static void freestyle_randomsetup_encrypt (freestyle_ctx *x)

for (i = 0; i < x->num_init_hashes; ++i)
{
R[i] = freestyle_encrypt_block (
freestyle_encrypt_block (
x,
R[i],
&x->init_hash [i]
);

Expand Down
2 changes: 1 addition & 1 deletion optimized/merged/freestyle.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 P. Arun Babu and Jithin Jose Thomas
* Copyright (c) 2019 P. Arun Babu and Jithin Jose Thomas
* arun DOT hbni AT gmail DOT com, jithinjosethomas AT gmail DOT com
*
* Permission to use, copy, modify, and distribute this software for any
Expand Down
2 changes: 1 addition & 1 deletion side-channel-attack-resistance/freestyle.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 P. Arun Babu and Jithin Jose Thomas
* Copyright (c) 2019 P. Arun Babu and Jithin Jose Thomas
* arun DOT hbni AT gmail DOT com, jithinjosethomas AT gmail DOT com
*
* Permission to use, copy, modify, and distribute this software for any
Expand Down
17 changes: 0 additions & 17 deletions test-password-hash.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
/*
* Copyright (c) 2018 P. Arun Babu and Jithin Jose Thomas
* arun DOT hbni AT gmail DOT com, jithinjosethomas AT gmail DOT com
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include <stdio.h>
#include <stdbool.h>
#include <assert.h>
Expand Down

0 comments on commit e1f1890

Please sign in to comment.