[Cryptech-Commits] [staging/core/hash/sha256] 22/32: Changed the python model to use a sliding window for W.

git at cryptech.is git at cryptech.is
Tue Mar 17 13:14:51 UTC 2015


This is an automated email from the git hooks/post-receive script.

paul at psgd.org pushed a commit to branch master
in repository staging/core/hash/sha256.

commit 588ce16c2ee374a640eb974da77804d873fa9e4a
Author: Joachim Strömbergson <joachim at secworks.se>
Date:   Wed Feb 26 03:09:05 2014 +0100

    Changed the python model to use a sliding window for W.
---
 src/model/sha256.py | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/src/model/sha256.py b/src/model/sha256.py
index a0535ba..afee05e 100755
--- a/src/model/sha256.py
+++ b/src/model/sha256.py
@@ -9,8 +9,8 @@
 # of the HW implementation as much as possible.
 #
 #
-# Author: Joachim Strombergson
-# (c) 2014 SUNET
+# Author: Joachim Strömbergson
+# Copyright (c) 2014 SUNET
 # 
 # Redistribution and use in source and binary forms, with or 
 # without modification, are permitted provided that the following 
@@ -147,7 +147,7 @@ class SHA256():
 
     def _sha256_round(self, round):
         self.k = self.K[round]
-        self.w = self.W[round]
+        self.w = self._next_w(round)
         self.t1 = self._T1(self.e, self.f, self.g, self.h, self.k, self.w)
         self.t2 = self._T2(self.a, self.b, self.c)
         self.h = self.g
@@ -160,20 +160,24 @@ class SHA256():
         self.a = (self.t1 + self.t2) & 0xffffffff
 
 
+    def _next_w(self, round):
+        if (round < 16):
+            return self.W[round]
+
+        else:
+            tmp_w = (self._delta1(self.W[14]) +
+                     self.W[9] + 
+                     self._delta0(self.W[1]) +
+                     self.W[0]) & 0xffffffff
+            for i in range(15):
+                self.W[i] = self.W[(i+1)]
+            self.W[15] = tmp_w
+            return tmp_w
+
+
     def _W_schedule(self, block):
-        for i in range(64):
-            if (i < 16):
-                self.W[i] = block[i]
-            else:
-                self.W[i] = (self._delta1(self.W[(i - 2)]) +
-                             self.W[(i - 7)] + 
-                             self._delta0(self.W[(i - 15)]) +
-                             self.W[(i - 16)]) & 0xffffffff
-        if (self.verbose):
-            print("W after schedule:")
-            for i in range(64):
-                print("W[%02d] = 0x%08x" % (i, self.W[i]))
-            print("")
+        for i in range(16):
+            self.W[i] = block[i]
 
 
     def _Ch(self, x, y, z):



More information about the Commits mailing list