switching to dedicated endian switching function
This commit is contained in:
parent
be13e6b437
commit
8b5e2b5775
|
@ -46,7 +46,6 @@ uint64_t sha2_large_common_const[80] = {
|
||||||
0x4cc5d4becb3e42b6LL, 0x597f299cfc657e2aLL, 0x5fcb6fab3ad6faecLL, 0x6c44198c4a475817LL
|
0x4cc5d4becb3e42b6LL, 0x597f299cfc657e2aLL, 0x5fcb6fab3ad6faecLL, 0x6c44198c4a475817LL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static const
|
static const
|
||||||
uint64_t change_endian64(uint64_t x){
|
uint64_t change_endian64(uint64_t x){
|
||||||
uint64_t r=0;
|
uint64_t r=0;
|
||||||
|
@ -59,8 +58,6 @@ uint64_t change_endian64(uint64_t x){
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static const
|
static const
|
||||||
uint64_t rotr64(uint64_t x, uint8_t n){
|
uint64_t rotr64(uint64_t x, uint8_t n){
|
||||||
return (x>>n)|(x<<(64-n));
|
return (x>>n)|(x<<(64-n));
|
||||||
|
@ -78,17 +75,26 @@ uint64_t rotl64(uint64_t x, uint8_t n){
|
||||||
#define SIGMA_a(x) (rotr64((x), 1) ^ rotr64((x), 8) ^ ((x)>>7))
|
#define SIGMA_a(x) (rotr64((x), 1) ^ rotr64((x), 8) ^ ((x)>>7))
|
||||||
#define SIGMA_b(x) (rotr64((x), 19) ^ rotl64((x), 3) ^ ((x)>>6))
|
#define SIGMA_b(x) (rotr64((x), 19) ^ rotl64((x), 3) ^ ((x)>>6))
|
||||||
|
|
||||||
|
static
|
||||||
|
void load_endian64_changed(uint8_t* dest, uint8_t* src, uint16_t words){
|
||||||
|
uint8_t i;
|
||||||
|
while(words--){
|
||||||
|
i = 7;
|
||||||
|
do{
|
||||||
|
*dest++ = src[i];
|
||||||
|
}while(i--);
|
||||||
|
src += 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void sha2_large_common_nextBlock(sha2_large_common_ctx_t* ctx, const void* block){
|
void sha2_large_common_nextBlock(sha2_large_common_ctx_t* ctx, const void* block){
|
||||||
uint64_t w[16], wx;
|
uint64_t w[16], wx;
|
||||||
uint64_t a[8];
|
uint64_t a[8];
|
||||||
uint64_t t1, t2;
|
uint64_t t1, t2;
|
||||||
const uint64_t *k=sha2_large_common_const;
|
const uint64_t *k=sha2_large_common_const;
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
i=16;
|
|
||||||
do{
|
load_endian64_changed((uint8_t*)w, (uint8_t*)block, 16);
|
||||||
w[16-i] = change_endian64(*((const uint64_t*)block));
|
|
||||||
block = (uint8_t*)block + 8;
|
|
||||||
}while(--i);
|
|
||||||
memcpy(a, ctx->h, 8*8);
|
memcpy(a, ctx->h, 8*8);
|
||||||
for(i=0; i<80; ++i){
|
for(i=0; i<80; ++i){
|
||||||
if(i<16){
|
if(i<16){
|
||||||
|
|
|
@ -40,11 +40,12 @@ uint32_t rotl32( uint32_t x, uint8_t n){
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
// #define CHANGE_ENDIAN32(x) (((x)<<24) | ((x)>>24) | (((x)& 0x0000ff00)<<8) | (((x)& 0x00ff0000)>>8))
|
// #define CHANGE_ENDIAN32(x) (((x)<<24) | ((x)>>24) | (((x)& 0x0000ff00)<<8) | (((x)& 0x00ff0000)>>8))
|
||||||
|
/*
|
||||||
static
|
static
|
||||||
uint32_t change_endian32(uint32_t x){
|
uint32_t change_endian32(uint32_t x){
|
||||||
return (((x)<<24) | ((x)>>24) | (((x)& 0x0000ff00)<<8) | (((x)& 0x00ff0000)>>8));
|
return (((x)<<24) | ((x)>>24) | (((x)& 0x0000ff00)<<8) | (((x)& 0x00ff0000)>>8));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/* sha256 functions as macros for speed and size, cause they are called only once */
|
/* sha256 functions as macros for speed and size, cause they are called only once */
|
||||||
|
|
||||||
|
@ -68,7 +69,16 @@ uint32_t k[]={
|
||||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static
|
||||||
|
void load_endian32_changed(uint8_t* dest, uint8_t* src, uint16_t words){
|
||||||
|
while(words--){
|
||||||
|
*dest++ = src[3];
|
||||||
|
*dest++ = src[2];
|
||||||
|
*dest++ = src[1];
|
||||||
|
*dest++ = src[0];
|
||||||
|
src += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* block must be, 512, Bit = 64, Byte, long !!!
|
* block must be, 512, Bit = 64, Byte, long !!!
|
||||||
|
@ -80,9 +90,7 @@ void sha2_small_common_nextBlock (sha2_small_common_ctx_t *state, const void* bl
|
||||||
|
|
||||||
/* init w */
|
/* init w */
|
||||||
#if defined LITTLE_ENDIAN
|
#if defined LITTLE_ENDIAN
|
||||||
for (i=0; i<16; ++i){
|
load_endian32_changed((uint8_t*)w, (uint8_t*)block, 16);
|
||||||
w[i]= change_endian32(((uint32_t*)block)[i]);
|
|
||||||
}
|
|
||||||
#elif defined BIG_ENDIAN
|
#elif defined BIG_ENDIAN
|
||||||
memcpy((void*)w, block, 64);
|
memcpy((void*)w, block, 64);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue