Skip to content

Commit

Permalink
DO NOT MERGE Faster blkxor in plain smix
Browse files Browse the repository at this point in the history
We decided not to merge this because:

    Now that we autodetect SSE2 support (which the original code didn't
    do) approximately 0% of x86 users should be running the non-SSE2
    code, and we would need to benchmark a range of different non-x86
    systems (and compilers) to get a sense of whether a change would
    help there.
    #334 (comment)
  • Loading branch information
gperciva committed Nov 30, 2023
1 parent 710793d commit fc48052
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/crypto/crypto_scrypt_smix.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "crypto_scrypt_smix.h"

static void blkcpy(uint32_t *, const uint32_t *, size_t);
static void blkxor(uint32_t *, const uint32_t *, size_t);
static void blkxor(unsigned char *, const unsigned char *, size_t);
static void salsa20_8(uint32_t[16]);
static void blockmix_salsa8(const uint32_t *, uint32_t *, uint32_t *, size_t);
static uint64_t integerify(const uint32_t *, size_t);
Expand All @@ -47,11 +47,11 @@ blkcpy(uint32_t * dest, const uint32_t * src, size_t len)
}

static void
blkxor(uint32_t * dest, const uint32_t * src, size_t len)
blkxor(unsigned char * dest, const unsigned char * src, size_t len)
{
size_t i;

for (i = 0; i < len / 4; i++)
for (i = 0; i < len; i++)
dest[i] ^= src[i];
}

Expand Down Expand Up @@ -116,15 +116,17 @@ blockmix_salsa8(const uint32_t * Bin, uint32_t * Bout, uint32_t * X, size_t r)
/* 2: for i = 0 to 2r - 1 do */
for (i = 0; i < 2 * r; i += 2) {
/* 3: X <-- H(X \xor B_i) */
blkxor(X, &Bin[i * 16], 64);
blkxor((unsigned char *)X,
(const unsigned char *)&Bin[i * 16], 64);
salsa20_8(X);

/* 4: Y_i <-- X */
/* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
blkcpy(&Bout[i * 8], X, 64);

/* 3: X <-- H(X \xor B_i) */
blkxor(X, &Bin[i * 16 + 16], 64);
blkxor((unsigned char *)X,
(const unsigned char *)&Bin[i * 16 + 16], 64);
salsa20_8(X);

/* 4: Y_i <-- X */
Expand Down Expand Up @@ -189,14 +191,16 @@ crypto_scrypt_smix(uint8_t * B, size_t r, uint64_t N, void * _v, void * XY)
j = integerify(X, r) & (N - 1);

/* 8: X <-- H(X \xor V_j) */
blkxor(X, &V[j * (32 * r)], 128 * r);
blkxor((unsigned char *)X,
(const unsigned char *)&V[j * (32 * r)], 128 * r);
blockmix_salsa8(X, Y, Z, r);

/* 7: j <-- Integerify(X) mod N */
j = integerify(Y, r) & (N - 1);

/* 8: X <-- H(X \xor V_j) */
blkxor(Y, &V[j * (32 * r)], 128 * r);
blkxor((unsigned char *)Y,
(const unsigned char *)&V[j * (32 * r)], 128 * r);
blockmix_salsa8(Y, X, Z, r);
}

Expand Down

0 comments on commit fc48052

Please sign in to comment.