mirror of https://github.com/GOSTSec/sgminer
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
3.3 KiB
97 lines
3.3 KiB
10 years ago
|
/*
|
||
|
* blake256 kernel implementation.
|
||
|
*
|
||
|
* ==========================(LICENSE BEGIN)============================
|
||
|
* Copyright (c) 2014 djm34
|
||
|
* Copyright (c) 2014 tpruvot
|
||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||
|
* a copy of this software and associated documentation files (the
|
||
|
* "Software"), to deal in the Software without restriction, including
|
||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||
|
* the following conditions:
|
||
|
*
|
||
|
* The above copyright notice and this permission notice shall be
|
||
|
* included in all copies or substantial portions of the Software.
|
||
|
*
|
||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||
|
*
|
||
|
* ===========================(LICENSE END)=============================
|
||
|
*
|
||
|
* @author djm34
|
||
|
*/
|
||
|
__constant static const int sigma[16][16] = {
|
||
|
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
|
||
|
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
|
||
|
{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
|
||
|
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
|
||
|
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
|
||
|
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
|
||
|
{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
|
||
|
{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
|
||
|
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
|
||
|
{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
|
||
|
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
|
||
|
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
|
||
|
{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
|
||
|
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
|
||
|
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
|
||
|
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 }
|
||
|
};
|
||
|
|
||
|
|
||
|
__constant static const sph_u32 c_IV256[8] = {
|
||
|
0x6A09E667, 0xBB67AE85,
|
||
|
0x3C6EF372, 0xA54FF53A,
|
||
|
0x510E527F, 0x9B05688C,
|
||
|
0x1F83D9AB, 0x5BE0CD19
|
||
|
};
|
||
|
|
||
|
/* Second part (64-80) msg never change, store it */
|
||
|
__constant static const sph_u32 c_Padding[16] = {
|
||
|
0, 0, 0, 0,
|
||
|
0x80000000, 0, 0, 0,
|
||
|
0, 0, 0, 0,
|
||
|
0, 1, 0, 640,
|
||
|
};
|
||
|
__constant static const sph_u32 c_u256[16] = {
|
||
|
0x243F6A88, 0x85A308D3,
|
||
|
0x13198A2E, 0x03707344,
|
||
|
0xA4093822, 0x299F31D0,
|
||
|
0x082EFA98, 0xEC4E6C89,
|
||
|
0x452821E6, 0x38D01377,
|
||
|
0xBE5466CF, 0x34E90C6C,
|
||
|
0xC0AC29B7, 0xC97C50DD,
|
||
|
0x3F84D5B5, 0xB5470917
|
||
|
};
|
||
|
|
||
|
#define GS(a,b,c,d,x) { \
|
||
|
const sph_u32 idx1 = sigma[r][x]; \
|
||
|
const sph_u32 idx2 = sigma[r][x+1]; \
|
||
|
v[a] += (m[idx1] ^ c_u256[idx2]) + v[b]; \
|
||
|
v[d] ^= v[a]; \
|
||
|
v[d] = SPH_ROTR32(v[d], 16); \
|
||
|
v[c] += v[d]; \
|
||
|
v[b] ^= v[c]; \
|
||
|
v[b] = SPH_ROTR32(v[b], 12); \
|
||
|
\
|
||
|
v[a] += (m[idx2] ^ c_u256[idx1]) + v[b]; \
|
||
|
v[d] ^= v[a]; \
|
||
|
v[d] = SPH_ROTR32(v[d], 8); \
|
||
|
v[c] += v[d]; \
|
||
|
v[b] ^= v[c]; \
|
||
|
v[b] = SPH_ROTR32(v[b], 7); \
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|