]> git.cryptolib.org Git - arm-crypto-lib.git/blobdiff - sha256/sha256.c
adding SHA-512
[arm-crypto-lib.git] / sha256 / sha256.c
index 83b3a438c21ff5d41fd7a65b0a65e4218d46af6f..3e66355313dd1c82a9ed693d0936faf01cf733b6 100644 (file)
@@ -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<<n) | (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[]={