X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=sha256%2Fsha256.c;h=3e66355313dd1c82a9ed693d0936faf01cf733b6;hb=92e0ee3f719d375d69300c7c1c48138d52330fcf;hp=83b3a438c21ff5d41fd7a65b0a65e4218d46af6f;hpb=5f46191d2615ebe2caa6e111b478031a34f20b9e;p=arm-crypto-lib.git diff --git a/sha256/sha256.c b/sha256/sha256.c index 83b3a43..3e66355 100644 --- a/sha256/sha256.c +++ b/sha256/sha256.c @@ -68,15 +68,20 @@ void sha256_init(sha256_ctx_t *state){ /** * rotate x right by n positions */ +static uint32_t rotr32( uint32_t x, uint8_t n){ return ((x>>n) | (x<<(32-n))); } +static +uint32_t rotl32( uint32_t x, uint8_t n){ + return ((x<>(32-n))); +} /*************************************************************************/ // #define CHANGE_ENDIAN32(x) (((x)<<24) | ((x)>>24) | (((x)& 0x0000ff00)<<8) | (((x)& 0x00ff0000)>>8)) - +static uint32_t change_endian32(uint32_t x){ return (((x)<<24) | ((x)>>24) | (((x)& 0x0000ff00)<<8) | (((x)& 0x00ff0000)>>8)); } @@ -89,10 +94,10 @@ uint32_t change_endian32(uint32_t x){ #define CH(x,y,z) (((x)&(y)) ^ ((~(x))&(z))) #define MAJ(x,y,z) (((x)&(y)) ^ ((x)&(z)) ^ ((y)&(z))) -#define SIGMA0(x) (rotr32((x),2) ^ rotr32((x),13) ^ rotr32((x),22)) -#define SIGMA1(x) (rotr32((x),6) ^ rotr32((x),11) ^ rotr32((x),25)) -#define SIGMA_a(x) (rotr32((x),7) ^ rotr32((x),18) ^ ((x)>>3)) -#define SIGMA_b(x) (rotr32((x),17) ^ rotr32((x),19) ^ ((x)>>10)) +#define SIGMA0(x) (rotr32((x),2) ^ rotr32((x),13) ^ rotl32((x),10)) +#define SIGMA1(x) (rotr32((x),6) ^ rotr32((x),11) ^ rotl32((x),7)) +#define SIGMA_a(x) (rotr32((x),7) ^ rotl32((x),14) ^ ((x)>>3)) +#define SIGMA_b(x) (rotl32((x),15) ^ rotl32((x),13) ^ ((x)>>10)) const uint32_t k[]={