Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: arun-babu/freestyle
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 11
Choose a base ref
...
head repository: arun-babu/freestyle
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 5 commits
  • 7 files changed
  • 1 contributor

Commits on Jul 6, 2022

  1. beautify

    arun-babu committed Jul 6, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3d4c414 View commit details

Commits on Aug 21, 2023

  1. add some consts

    arun-babu authored Aug 21, 2023
    Copy the full SHA
    1377cc3 View commit details
  2. Copy the full SHA
    908648e View commit details
  3. Copy the full SHA
    5932117 View commit details
  4. Update test-timing.c

    arun-babu authored Aug 21, 2023
    Copy the full SHA
    8697e44 View commit details
Showing with 67 additions and 68 deletions.
  1. +31 −33 freestyle.c
  2. +18 −18 freestyle.h
  3. +7 −6 optimized/merged/freestyle.h
  4. +8 −8 side-channel-attack-resistance/freestyle.c
  5. +1 −1 test-functionality.c
  6. +1 −1 test-password-hash.c
  7. +1 −1 test-timing.c
64 changes: 31 additions & 33 deletions freestyle.c
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ static u8 gcd (u8 a, u8 b)
{
while (b != 0)
{
u8 r = a % b;
const u8 r = a % b;

a = b;
b = r;
@@ -38,18 +38,18 @@ static u8 gcd (u8 a, u8 b)

static void freestyle_column_round (u32 x[16])
{
QR (x[0], x[4], x[ 8], x[12])
QR (x[1], x[5], x[ 9], x[13])
QR (x[2], x[6], x[10], x[14])
QR (x[3], x[7], x[11], x[15])
QR (x[0], x[4], x[ 8], x[12]);
QR (x[1], x[5], x[ 9], x[13]);
QR (x[2], x[6], x[10], x[14]);
QR (x[3], x[7], x[11], x[15]);
}

static void freestyle_diagonal_round (u32 x[16])
{
QR (x[0], x[5], x[10], x[15])
QR (x[1], x[6], x[11], x[12])
QR (x[2], x[7], x[ 8], x[13])
QR (x[3], x[4], x[ 9], x[14])
QR (x[0], x[5], x[10], x[15]);
QR (x[1], x[6], x[11], x[12]);
QR (x[2], x[7], x[ 8], x[13]);
QR (x[3], x[4], x[ 9], x[14]);
}

static void freestyle_precompute_rounds (freestyle_ctx* const x)
@@ -93,15 +93,15 @@ static void freestyle_keysetup (
constants = sigma;
}

x->input[KEY4] = U8TO32_LITTLE(key + 0);
x->input[KEY5] = U8TO32_LITTLE(key + 4);
x->input[KEY6] = U8TO32_LITTLE(key + 8);
x->input[KEY7] = U8TO32_LITTLE(key + 12);
x->input[KEY4] = U8TO32_LITTLE(key + 0);
x->input[KEY5] = U8TO32_LITTLE(key + 4);
x->input[KEY6] = U8TO32_LITTLE(key + 8);
x->input[KEY7] = U8TO32_LITTLE(key + 12);

x->input[CONSTANT0] = U8TO32_LITTLE(constants + 0);
x->input[CONSTANT1] = U8TO32_LITTLE(constants + 4);
x->input[CONSTANT2] = U8TO32_LITTLE(constants + 8);
x->input[CONSTANT3] = U8TO32_LITTLE(constants + 12);
x->input[CONSTANT0] = U8TO32_LITTLE(constants + 0);
x->input[CONSTANT1] = U8TO32_LITTLE(constants + 4);
x->input[CONSTANT2] = U8TO32_LITTLE(constants + 8);
x->input[CONSTANT3] = U8TO32_LITTLE(constants + 12);
}

static void freestyle_ivsetup (
@@ -171,8 +171,6 @@ static u8 freestyle_hash (
const u8 previous_hash,
const u8 rounds)
{
u8 hash;

u32 temp1 = rounds;
u32 temp2 = previous_hash;

@@ -181,7 +179,7 @@ static u8 freestyle_hash (
AXR (temp1, cipher_state[ 9], temp2, 8);
AXR (temp2, cipher_state[12], temp1, 7);

hash = temp1 & 0xFF;
const u8 hash = temp1 & 0xFF;

return hash;
}
@@ -198,10 +196,11 @@ static u8 freestyle_xcrypt_block (
u8 hash = 0;
u32 output[16];

u8 rounds = do_encryption ?
freestyle_random_round_number (x): x->max_rounds;
const u8 rounds = do_encryption ?
freestyle_random_round_number (x):
x->max_rounds;

bool do_decryption = ! do_encryption;
const bool do_decryption = ! do_encryption;

bool hash_collided [MAX_HASH_VALUES];

@@ -764,8 +763,8 @@ void freestyle_hash_password (
// last byte of IV is the password length
key_and_iv [43] = password_len;

u8 *key = key_and_iv;
u8 *iv = key_and_iv + 32;
const u8* const key = key_and_iv;
const u8* const iv = key_and_iv + 32;

freestyle_init_encrypt (
&x,
@@ -830,7 +829,7 @@ void freestyle_hash_password_with_pepper (

u8 expected_hash;

int password_len = strlen (password);
const int password_len = strlen (password);

assert (password_len >= 1);
assert (password_len <= 43);
@@ -855,8 +854,8 @@ void freestyle_hash_password_with_pepper (
// last byte of IV is the password length
key_and_iv [43] = password_len;

u8 *key = key_and_iv;
u8 *iv = key_and_iv + 32;
const u8* const key = key_and_iv;
const u8* const iv = key_and_iv + 32;

freestyle_init_encrypt_with_pepper (
&x,
@@ -928,9 +927,8 @@ bool freestyle_verify_password_hash (

u8 key_and_iv [44];

u8 expected_hash = hash [num_init_hashes];

int password_len = strlen (password);
u8 expected_hash = hash [num_init_hashes];
const int password_len = strlen (password);

assert (password_len >= 1);
assert (password_len <= 43);
@@ -955,8 +953,8 @@ bool freestyle_verify_password_hash (
// last byte of IV is the password length
key_and_iv [43] = password_len;

u8 *key = key_and_iv;
u8 *iv = key_and_iv + 32;
const u8* const key = key_and_iv;
const u8* const iv = key_and_iv + 32;

if (! freestyle_init_decrypt (
&x,
36 changes: 18 additions & 18 deletions freestyle.h
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@
#define KEY5 (9)
#define KEY6 (10)
#define KEY7 (11)
#define COUNTER (12)
#define COUNTER (12)
#define IV0 (13)
#define IV1 (14)
#define IV2 (15)
@@ -76,21 +76,20 @@ typedef uint32_t u32;
#define U8V(v) ((u8)(v) & U8C(0xFF))
#define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF))

#define ROTL32(v, n) \
(U32V((v) << (n)) | ((v) >> (32 - (n))))
#define ROTL32(v, n) (U32V((v) << (n)) | ((v) >> (32 - (n))))

#define U8TO32_LITTLE(p) \
(((u32)((p)[0]) ) | \
((u32)((p)[1]) << 8) | \
((u32)((p)[2]) << 16) | \
#define U8TO32_LITTLE(p) \
(((u32)((p)[0]) ) | \
((u32)((p)[1]) << 8) | \
((u32)((p)[2]) << 16) | \
((u32)((p)[3]) << 24))

#define U32TO8_LITTLE(p, v) \
do { \
(p)[0] = U8V((v) ); \
(p)[1] = U8V((v) >> 8); \
(p)[2] = U8V((v) >> 16); \
(p)[3] = U8V((v) >> 24); \
#define U32TO8_LITTLE(p, v) \
do { \
(p)[0] = U8V((v) ); \
(p)[1] = U8V((v) >> 8); \
(p)[2] = U8V((v) >> 16); \
(p)[3] = U8V((v) >> 24); \
} while (0)

#define ROTATE(v,c) (ROTL32(v,c))
@@ -99,11 +98,12 @@ typedef uint32_t u32;
#define MINUS(v,w) (U32V((v) - (w)))
#define PLUSONE(v) (PLUS((v),1))

#define QR(a,b,c,d) \
a = PLUS(a,b); d = ROTATE(XOR(d,a),16); \
c = PLUS(c,d); b = ROTATE(XOR(b,c),12); \
a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \
c = PLUS(c,d); b = ROTATE(XOR(b,c), 7);
#define QR(a,b,c,d) { \
a = PLUS(a,b); d = ROTATE(XOR(d,a), 16); \
c = PLUS(c,d); b = ROTATE(XOR(b,c), 12); \
a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \
c = PLUS(c,d); b = ROTATE(XOR(b,c), 7); \
}

static const char sigma[16] = "expand 32-byte k";
static const char tau[16] = "expand 16-byte k";
13 changes: 7 additions & 6 deletions optimized/merged/freestyle.h
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@
#define KEY5 (9)
#define KEY6 (10)
#define KEY7 (11)
#define COUNTER (12)
#define COUNTER (12)
#define IV0 (13)
#define IV1 (14)
#define IV2 (15)
@@ -99,11 +99,12 @@ typedef uint32_t u32;
#define MINUS(v,w) (U32V((v) - (w)))
#define PLUSONE(v) (PLUS((v),1))

#define QR(a,b,c,d) \
a = PLUS(a,b); d = ROTATE(XOR(d,a),16); \
c = PLUS(c,d); b = ROTATE(XOR(b,c),12); \
a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \
c = PLUS(c,d); b = ROTATE(XOR(b,c), 7);
#define QR(a,b,c,d) { \
a = PLUS(a,b); d = ROTATE(XOR(d,a), 16); \
c = PLUS(c,d); b = ROTATE(XOR(b,c), 12); \
a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \
c = PLUS(c,d); b = ROTATE(XOR(b,c), 7); \
}

static const char sigma[16] = "expand 32-byte k";
static const char tau[16] = "expand 16-byte k";
16 changes: 8 additions & 8 deletions side-channel-attack-resistance/freestyle.c
Original file line number Diff line number Diff line change
@@ -62,18 +62,18 @@ static u8 gcd (u8 a, u8 b)

static void freestyle_column_round (u32 x[16])
{
QR (x[0], x[4], x[ 8], x[12])
QR (x[1], x[5], x[ 9], x[13])
QR (x[2], x[6], x[10], x[14])
QR (x[3], x[7], x[11], x[15])
QR (x[0], x[4], x[ 8], x[12]);
QR (x[1], x[5], x[ 9], x[13]);
QR (x[2], x[6], x[10], x[14]);
QR (x[3], x[7], x[11], x[15]);
}

static void freestyle_diagonal_round (u32 x[16])
{
QR (x[0], x[5], x[10], x[15])
QR (x[1], x[6], x[11], x[12])
QR (x[2], x[7], x[ 8], x[13])
QR (x[3], x[4], x[ 9], x[14])
QR (x[0], x[5], x[10], x[15]);
QR (x[1], x[6], x[11], x[12]);
QR (x[2], x[7], x[ 8], x[13]);
QR (x[3], x[4], x[ 9], x[14]);
}

static void freestyle_precompute_rounds (freestyle_ctx* const x)
2 changes: 1 addition & 1 deletion test-functionality.c
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@

#define MSG_LEN (64)

int main ()
int main (void)
{
int i, j;

2 changes: 1 addition & 1 deletion test-password-hash.c
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@

#include "test-password-hash.h"

int main ()
int main (void)
{
int i;

2 changes: 1 addition & 1 deletion test-timing.c
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@

#define MSG_LEN (1111)

int main ()
int main (void)
{
int i;