Skip to content

Commit

Permalink
Better Names for Preprocessor Directives
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostlander committed Jul 9, 2018
1 parent 7e2f17f commit 89c04c7
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 99 deletions.
2 changes: 1 addition & 1 deletion LICENCE
@@ -1,7 +1,7 @@
Copyright (c) 2009 Colin Percival, 2011 ArtForz
Copyright (c) 2012 Andrew Moon (floodyberry)
Copyright (c) 2012 Samuel Neves <sneves@dei.uc.pt>
Copyright (c) 2014-2016 John Doering <ghostlander@phoenixcoin.org>
Copyright (c) 2014-2018 John Doering <ghostlander@phoenixcoin.org>
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -4,11 +4,11 @@ NeoScrypt
NeoScrypt is a strong memory intensive key derivation function.

Compile time definitions:
- -DSHA256 enables optional SHA-256 support (Scrypt compatibility);
- -DBLAKE256 enables optional BLAKE-256 support;
- -DOPT enables FastKDF performance optimisations;
- -DASM enables 32-bit and 64-bit assembly optimisations;
- -DMINER_4WAY enables 4-way mining per thread (requires -DASM).
- -DNEOSCRYPT_SHA256 enables optional SHA-256 support (Scrypt compatibility);
- -DNEOSCRYPT_BLAKE256 enables optional BLAKE-256 support;
- -DNEOSCRYPT_OPT enables FastKDF performance optimisations;
- -DNEOSCRYPT_ASM enables 32-bit and 64-bit assembly optimisations;
- -DNEOSCRYPT_MINER_4WAY enables 4-way mining per thread (requires -DNEOSCRYPT_ASM).

There are also test vectors and benchmarks available.

Expand Down
2 changes: 1 addition & 1 deletion build.sh
@@ -1,6 +1,6 @@
#!/bin/sh

DEFINES="-DASM -DOPT -DMINER_4WAY -DSHA256"
DEFINES="-DNEOSCRYPT_ASM -DNEOSCRYPT_OPT -DNEOSCRYPT_MINER_4WAY -DNEOSCRYPT_SHA256"

CC="gcc"
CFLAGS="-Wall -O2 -fomit-frame-pointer -fno-stack-protector"
Expand Down
50 changes: 25 additions & 25 deletions neoscrypt.c
Expand Up @@ -35,7 +35,7 @@
#include "neoscrypt.h"


#ifdef SHA256
#ifdef NEOSCRYPT_SHA256

/* SHA-256 */

Expand Down Expand Up @@ -274,10 +274,10 @@ void neoscrypt_pbkdf2_sha256(const uchar *password, uint password_len,
}
}

#endif /* SHA256 */
#endif /* NEOSCRYPT_SHA256 */


#ifdef BLAKE256
#ifdef NEOSCRYPT_BLAKE256

/* BLAKE-256 */

Expand Down Expand Up @@ -566,12 +566,12 @@ static void neoscrypt_pbkdf2_blake256(const uchar *password,
}
}

#endif /* BLAKE256 */
#endif /* NEOSCRYPT_BLAKE256 */


/* NeoScrypt */

#ifdef ASM
#ifdef NEOSCRYPT_ASM

extern void neoscrypt_copy(void *dstp, const void *srcp, uint len);
extern void neoscrypt_erase(void *dstp, uint len);
Expand Down Expand Up @@ -748,7 +748,7 @@ void neoscrypt_xor(void *dstp, const void *srcp, uint len) {
dst[i] ^= src[i];
}

#endif /* ASM */
#endif /* NEOSCRYPT_ASM */


/* BLAKE2s */
Expand Down Expand Up @@ -783,7 +783,7 @@ static const uint blake2s_IV[8] = {
0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19
};

#ifdef ASM
#ifdef NEOSCRYPT_ASM

extern void blake2s_compress(blake2s_state *S);

Expand Down Expand Up @@ -2192,7 +2192,7 @@ static void blake2s_compress(blake2s_state *S) {
S->h[7] ^= v[7] ^ v[15];
}

#endif /* ASM */
#endif /* NEOSCRYPT_ASM */

static void blake2s_update(blake2s_state *S, const uchar *input,
uint input_size) {
Expand Down Expand Up @@ -2264,7 +2264,7 @@ void neoscrypt_blake2s(const void *input, const uint input_size,
neoscrypt_copy(output, S, output_size);
}

#ifndef OPT
#ifndef NEOSCRYPT_OPT

#define FASTKDF_BUFFER_SIZE 256U

Expand Down Expand Up @@ -2362,7 +2362,7 @@ void neoscrypt_fastkdf(const uchar *password, uint password_len,

#else

#ifdef ASM
#ifdef NEOSCRYPT_ASM

extern void neoscrypt_fastkdf_opt(const uchar *password, const uchar *salt,
uchar *output, uint mode);
Expand Down Expand Up @@ -2459,12 +2459,12 @@ void neoscrypt_fastkdf_opt(const uchar *password, const uchar *salt,
}
}

#endif /* ASM */
#endif /* NEOSCRYPT_ASM */

#endif /* !(OPT) */
#endif /* !(NEOSCRYPT_OPT) */


#ifndef ASM
#ifndef NEOSCRYPT_ASM

/* Configurable optimised block mixer */
static void neoscrypt_blkmix(uint *X, uint *Y, uint r, uint mixmode) {
Expand Down Expand Up @@ -2604,22 +2604,22 @@ void neoscrypt(const uchar *password, uchar *output, uint profile) {

default:
case(0x0):
#ifdef OPT
#ifdef NEOSCRYPT_OPT
neoscrypt_fastkdf_opt(password, password, (uchar *) X, 0);
#else
neoscrypt_fastkdf(password, 80, password, 80, 32,
(uchar *) X, r * 2 * BLOCK_SIZE);
#endif
break;

#ifdef SHA256
#ifdef NEOSCRYPT_SHA256
case(0x1):
neoscrypt_pbkdf2_sha256(password, 80, password, 80, 1,
(uchar *) X, r * 2 * BLOCK_SIZE);
break;
#endif

#ifdef BLAKE256
#ifdef NEOSCRYPT_BLAKE256
case(0x2):
neoscrypt_pbkdf2_blake256(password, 80, password, 80, 1,
(uchar *) X, r * 2 * BLOCK_SIZE);
Expand Down Expand Up @@ -2677,22 +2677,22 @@ void neoscrypt(const uchar *password, uchar *output, uint profile) {

default:
case(0x0):
#ifdef OPT
#ifdef NEOSCRYPT_OPT
neoscrypt_fastkdf_opt(password, (uchar *) X, output, 1);
#else
neoscrypt_fastkdf(password, 80, (uchar *) X,
r * 2 * BLOCK_SIZE, 32, output, 32);
#endif
break;

#ifdef SHA256
#ifdef NEOSCRYPT_SHA256
case(0x1):
neoscrypt_pbkdf2_sha256(password, 80, (uchar *) X,
r * 2 * BLOCK_SIZE, 1, output, 32);
break;
#endif

#ifdef BLAKE256
#ifdef NEOSCRYPT_BLAKE256
case(0x2):
neoscrypt_pbkdf2_blake256(password, 80, (uchar *) X,
r * 2 * BLOCK_SIZE, 1, output, 32);
Expand All @@ -2703,10 +2703,10 @@ void neoscrypt(const uchar *password, uchar *output, uint profile) {

}

#endif /* !(ASM) */
#endif /* !(NEOSCRYPT_ASM) */


#if defined(ASM) && defined(MINER_4WAY)
#if defined(NEOSCRYPT_ASM) && defined(NEOSCRYPT_MINER_4WAY)

extern void neoscrypt_xor_salsa_4way(uint *X, uint *X0, uint *Y, uint double_rounds);
extern void neoscrypt_xor_chacha_4way(uint *Z, uint *Z0, uint *Y, uint double_rounds);
Expand Down Expand Up @@ -2910,7 +2910,7 @@ void neoscrypt_4way(const uchar *password, uchar *output, uchar *scratchpad) {
(uchar *) &scratchpad[0], 1);
}

#ifdef SHA256
#ifdef NEOSCRYPT_SHA256
/* 4-way Scrypt(1024, 1, 1) with Salsa20/8 */
void scrypt_4way(const uchar *password, uchar *output, uchar *scratchpad) {
const uint N = 1024, r = 1, double_rounds = 4;
Expand Down Expand Up @@ -2960,7 +2960,7 @@ void scrypt_4way(const uchar *password, uchar *output, uchar *scratchpad) {
(uchar *) &Y[k * r * 32], r * 128, 1,
(uchar *) &output[k * 32], 32);
}
#endif /* SHA256 */
#endif /* NEOSCRYPT_SHA256 */


extern void blake2s_compress_4way(void *T);
Expand Down Expand Up @@ -3242,9 +3242,9 @@ void neoscrypt_fastkdf_4way(const uchar *password, const uchar *salt,

}

#endif /* (ASM) && (MINER_4WAY) */
#endif /* (NEOSCRYPT_ASM) && (NEOSCRYPT_MINER_4WAY) */

#ifndef ASM
#ifndef NEOSCRYPT_ASM
uint cpu_vec_exts() {

/* No assembly, no extensions */
Expand Down
4 changes: 2 additions & 2 deletions neoscrypt.h
Expand Up @@ -13,11 +13,11 @@ void neoscrypt_copy(void *dstp, const void *srcp, unsigned int len);
void neoscrypt_erase(void *dstp, unsigned int len);
void neoscrypt_xor(void *dstp, const void *srcp, unsigned int len);

#if defined(ASM) && defined(MINER_4WAY)
#if defined(NEOSCRYPT_ASM) && defined(NEOSCRYPT_MINER_4WAY)
void neoscrypt_4way(const unsigned char *password, unsigned char *output,
unsigned char *scratchpad);

#ifdef SHA256
#ifdef NEOSCRYPT_SHA256
void scrypt_4way(const unsigned char *password, unsigned char *output,
unsigned char *scratchpad);
#endif
Expand Down

0 comments on commit 89c04c7

Please sign in to comment.