From 588ce16c2ee374a640eb974da77804d873fa9e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Wed, 26 Feb 2014 03:09:05 +0100 Subject: Changed the python model to use a sliding window for W. --- src/model/sha256.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'src/model') 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): -- cgit v1.2.3