From 2cf54c4aefe0d5181db922a6d8ebf229e3e4d251 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 23 Aug 2013 22:34:03 +0400 Subject: [PATCH] Rename scrypt_mine.(cpp|h) to scrypt.(cpp|h) --- novacoin-qt.pro | 4 +- src/main.cpp | 1 - src/main.h | 2 +- src/makefile.bsd | 2 +- src/makefile.linux-mingw | 2 +- src/makefile.mingw | 2 +- src/makefile.osx | 2 +- src/makefile.unix | 2 +- src/scrypt.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++++ src/scrypt.h | 13 ++++++++ src/scrypt_mine.cpp | 76 ---------------------------------------------- src/scrypt_mine.h | 13 -------- 12 files changed, 97 insertions(+), 98 deletions(-) create mode 100644 src/scrypt.cpp create mode 100644 src/scrypt.h delete mode 100644 src/scrypt_mine.cpp delete mode 100644 src/scrypt_mine.h diff --git a/novacoin-qt.pro b/novacoin-qt.pro index 5922e05..a9614e9 100644 --- a/novacoin-qt.pro +++ b/novacoin-qt.pro @@ -127,7 +127,7 @@ HEADERS += src/qt/bitcoingui.h \ src/util.h \ src/uint256.h \ src/kernel.h \ - src/scrypt_mine.h \ + src/scrypt.h \ src/pbkdf2.h \ src/serialize.h \ src/strlcpy.h \ @@ -244,7 +244,7 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \ src/kernel.cpp \ src/scrypt-x86.S \ src/scrypt-x86_64.S \ - src/scrypt_mine.cpp \ + src/scrypt.cpp \ src/pbkdf2.cpp RESOURCES += \ diff --git a/src/main.cpp b/src/main.cpp index 4b0caf8..77d5acd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,7 +10,6 @@ #include "init.h" #include "ui_interface.h" #include "kernel.h" -#include "scrypt_mine.h" #include #include #include diff --git a/src/main.h b/src/main.h index 3711793..8b92292 100644 --- a/src/main.h +++ b/src/main.h @@ -9,7 +9,7 @@ #include "sync.h" #include "net.h" #include "script.h" -#include "scrypt_mine.h" +#include "scrypt.h" #include diff --git a/src/makefile.bsd b/src/makefile.bsd index eec1a3e..d493919 100644 --- a/src/makefile.bsd +++ b/src/makefile.bsd @@ -131,7 +131,7 @@ OBJS= \ obj/noui.o \ obj/kernel.o \ obj/pbkdf2.o \ - obj/scrypt_mine.o \ + obj/scrypt.o \ obj/scrypt-x86.o \ obj/scrypt-x86_64.o diff --git a/src/makefile.linux-mingw b/src/makefile.linux-mingw index 2013486..466987a 100644 --- a/src/makefile.linux-mingw +++ b/src/makefile.linux-mingw @@ -85,7 +85,7 @@ OBJS= \ obj/noui.o \ obj/kernel.o \ obj/pbkdf2.o \ - obj/scrypt_mine.o \ + obj/scrypt.o \ obj/scrypt-x86.o \ obj/scrypt-x86_64.o diff --git a/src/makefile.mingw b/src/makefile.mingw index 8b3311a..6d91c9d 100644 --- a/src/makefile.mingw +++ b/src/makefile.mingw @@ -81,7 +81,7 @@ OBJS= \ obj/noui.o \ obj/kernel.o \ obj/pbkdf2.o \ - obj/scrypt_mine.o \ + obj/scrypt.o \ obj/scrypt-x86.o \ obj/scrypt-x86_64.o diff --git a/src/makefile.osx b/src/makefile.osx index a76f277..01c0085 100644 --- a/src/makefile.osx +++ b/src/makefile.osx @@ -99,7 +99,7 @@ OBJS= \ obj/noui.o \ obj/pbkdf2.o \ obj/kernel.o \ - obj/scrypt_mine.o \ + obj/scrypt.o \ obj/scrypt-x86.o \ obj/scrypt-x86_64.o diff --git a/src/makefile.unix b/src/makefile.unix index c668788..4319769 100644 --- a/src/makefile.unix +++ b/src/makefile.unix @@ -130,7 +130,7 @@ OBJS= \ obj/noui.o \ obj/kernel.o \ obj/pbkdf2.o \ - obj/scrypt_mine.o \ + obj/scrypt.o \ obj/scrypt-x86.o \ obj/scrypt-x86_64.o diff --git a/src/scrypt.cpp b/src/scrypt.cpp new file mode 100644 index 0000000..7cc1b30 --- /dev/null +++ b/src/scrypt.cpp @@ -0,0 +1,76 @@ +/*- + * Copyright 2009 Colin Percival, 2011 ArtForz, 2011 pooler, 2013 Balthazar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file was originally written by Colin Percival as part of the Tarsnap + * online backup system. + */ + +#include +#include + +#include "scrypt.h" +#include "pbkdf2.h" + +#include "util.h" +#include "net.h" + +#define SCRYPT_BUFFER_SIZE (131072 + 63) + +#if defined (__x86_64__) || defined (__i386__) +extern "C" void scrypt_core(uint32_t *X, uint32_t *V); +#else +// TODO: Add cross-platform scrypt_core implementation +#endif + +/* cpu and memory intensive function to transform a 80 byte buffer into a 32 byte output + scratchpad size needs to be at least 63 + (128 * r * p) + (256 * r + 64) + (128 * r * N) bytes + r = 1, p = 1, N = 1024 + */ + +uint256 scrypt(const void* input, size_t inputlen, void *scratchpad) +{ + uint32_t *V; + uint32_t X[32]; + uint256 result = 0; + V = (uint32_t *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63)); + + PBKDF2_SHA256((const uint8_t*)input, inputlen, (const uint8_t*)input, inputlen, 1, (uint8_t *)X, 128); + scrypt_core(X, V); + PBKDF2_SHA256((const uint8_t*)input, inputlen, (uint8_t *)X, 128, 1, (uint8_t*)&result, 32); + + return result; +} + +uint256 scrypt_hash(const void* input, size_t inputlen) +{ + unsigned char scratchpad[SCRYPT_BUFFER_SIZE]; + return scrypt(input, inputlen, scratchpad); +} + +uint256 scrypt_blockhash(const void* input) +{ + unsigned char scratchpad[SCRYPT_BUFFER_SIZE]; + return scrypt(input, 80, scratchpad); +} diff --git a/src/scrypt.h b/src/scrypt.h new file mode 100644 index 0000000..2d2112d --- /dev/null +++ b/src/scrypt.h @@ -0,0 +1,13 @@ +#ifndef SCRYPT_MINE_H +#define SCRYPT_MINE_H + +#include +#include + +#include "util.h" +#include "net.h" + +uint256 scrypt_hash(const void* input, size_t inputlen); +uint256 scrypt_blockhash(const void* input); + +#endif // SCRYPT_MINE_H diff --git a/src/scrypt_mine.cpp b/src/scrypt_mine.cpp deleted file mode 100644 index 6636097..0000000 --- a/src/scrypt_mine.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * Copyright 2009 Colin Percival, 2011 ArtForz, 2011 pooler, 2013 Balthazar - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file was originally written by Colin Percival as part of the Tarsnap - * online backup system. - */ - -#include -#include - -#include "scrypt_mine.h" -#include "pbkdf2.h" - -#include "util.h" -#include "net.h" - -#define SCRYPT_BUFFER_SIZE (131072 + 63) - -#if defined (__x86_64__) || defined (__i386__) -extern "C" void scrypt_core(uint32_t *X, uint32_t *V); -#else -// TODO: Add cross-platform scrypt_core implementation -#endif - -/* cpu and memory intensive function to transform a 80 byte buffer into a 32 byte output - scratchpad size needs to be at least 63 + (128 * r * p) + (256 * r + 64) + (128 * r * N) bytes - r = 1, p = 1, N = 1024 - */ - -uint256 scrypt(const void* input, size_t inputlen, void *scratchpad) -{ - uint32_t *V; - uint32_t X[32]; - uint256 result = 0; - V = (uint32_t *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63)); - - PBKDF2_SHA256((const uint8_t*)input, inputlen, (const uint8_t*)input, inputlen, 1, (uint8_t *)X, 128); - scrypt_core(X, V); - PBKDF2_SHA256((const uint8_t*)input, inputlen, (uint8_t *)X, 128, 1, (uint8_t*)&result, 32); - - return result; -} - -uint256 scrypt_hash(const void* input, size_t inputlen) -{ - unsigned char scratchpad[SCRYPT_BUFFER_SIZE]; - return scrypt(input, inputlen, scratchpad); -} - -uint256 scrypt_blockhash(const void* input) -{ - unsigned char scratchpad[SCRYPT_BUFFER_SIZE]; - return scrypt(input, 80, scratchpad); -} diff --git a/src/scrypt_mine.h b/src/scrypt_mine.h deleted file mode 100644 index 2d2112d..0000000 --- a/src/scrypt_mine.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef SCRYPT_MINE_H -#define SCRYPT_MINE_H - -#include -#include - -#include "util.h" -#include "net.h" - -uint256 scrypt_hash(const void* input, size_t inputlen); -uint256 scrypt_blockhash(const void* input); - -#endif // SCRYPT_MINE_H -- 1.7.1