```%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Copyright: 2010 Integrated Sytems Laboratory, ETH Zurich
%%            http://www.iis.ee.ethz.ch/~sha3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
global Q Qb W Wb M Mb H Hb;

Mb = num2bin(qnt32,M(:));
Mb = str2num(Mb(:));
Mb = reshape(Mb, 16, 32);  % M is stored into Mb as a binary matrix

Hb = num2bin(qnt32,H(:));
Hb = str2num(Hb(:));
Hb = reshape(Hb, 16, 32);   % H is stored into Hb as binary matrix

W(0+1,:) = mod(bin2num(qnt32,sprintf('%-1d', xor(Mb(5+1,:),Hb(5+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(7+1,:),Hb(7+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(10+1,:),Hb(10+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(13+1,:),Hb(13+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(14+1,:),Hb(14+1,:)))), 2^32);
W(1+1,:) = mod(bin2num(qnt32,sprintf('%-1d', xor(Mb(6+1,:),Hb(6+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(8+1,:),Hb(8+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(11+1,:),Hb(11+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(14+1,:),Hb(14+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(15+1,:),Hb(15+1,:)))), 2^32);
W(2+1,:) = mod(bin2num(qnt32,sprintf('%-1d', xor(Mb(0+1,:),Hb(0+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(7+1,:),Hb(7+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(9+1,:),Hb(9+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(12+1,:),Hb(12+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(15+1,:),Hb(15+1,:)))), 2^32);
W(3+1,:) = mod(bin2num(qnt32,sprintf('%-1d', xor(Mb(0+1,:),Hb(0+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(1+1,:),Hb(1+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(8+1,:),Hb(8+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(10+1,:),Hb(10+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(13+1,:),Hb(13+1,:)))), 2^32);
W(4+1,:) = mod(bin2num(qnt32,sprintf('%-1d', xor(Mb(1+1,:),Hb(1+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(2+1,:),Hb(2+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(9+1,:),Hb(9+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(11+1,:),Hb(11+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(14+1,:),Hb(14+1,:)))), 2^32);
W(5+1,:) = mod(bin2num(qnt32,sprintf('%-1d', xor(Mb(3+1,:),Hb(3+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(2+1,:),Hb(2+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(10+1,:),Hb(10+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(12+1,:),Hb(12+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(15+1,:),Hb(15+1,:)))), 2^32);
W(6+1,:) = mod(bin2num(qnt32,sprintf('%-1d', xor(Mb(4+1,:),Hb(4+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(0+1,:),Hb(0+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(3+1,:),Hb(3+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(11+1,:),Hb(11+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(13+1,:),Hb(13+1,:)))), 2^32);
W(7+1,:) = mod(bin2num(qnt32,sprintf('%-1d', xor(Mb(1+1,:),Hb(1+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(4+1,:),Hb(4+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(5+1,:),Hb(5+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(12+1,:),Hb(12+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(14+1,:),Hb(14+1,:)))), 2^32);
W(8+1,:) = mod(bin2num(qnt32,sprintf('%-1d', xor(Mb(2+1,:),Hb(2+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(5+1,:),Hb(5+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(6+1,:),Hb(6+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(13+1,:),Hb(13+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(15+1,:),Hb(15+1,:)))), 2^32);
W(9+1,:) = mod(bin2num(qnt32,sprintf('%-1d', xor(Mb(0+1,:),Hb(0+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(3+1,:),Hb(3+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(6+1,:),Hb(6+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(7+1,:),Hb(7+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(14+1,:),Hb(14+1,:)))), 2^32);
W(10+1,:) = mod(bin2num(qnt32,sprintf('%-1d', xor(Mb(8+1,:),Hb(8+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(1+1,:),Hb(1+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(4+1,:),Hb(4+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(7+1,:),Hb(7+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(15+1,:),Hb(15+1,:)))), 2^32);
W(11+1,:) = mod(bin2num(qnt32,sprintf('%-1d', xor(Mb(8+1,:),Hb(8+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(0+1,:),Hb(0+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(2+1,:),Hb(2+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(5+1,:),Hb(5+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(9+1,:),Hb(9+1,:)))), 2^32);
W(12+1,:) = mod(bin2num(qnt32,sprintf('%-1d', xor(Mb(1+1,:),Hb(1+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(3+1,:),Hb(3+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(6+1,:),Hb(6+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(9+1,:),Hb(9+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(10+1,:),Hb(10+1,:)))), 2^32);
W(13+1,:) = mod(bin2num(qnt32,sprintf('%-1d', xor(Mb(2+1,:),Hb(2+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(4+1,:),Hb(4+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(7+1,:),Hb(7+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(10+1,:),Hb(10+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(11+1,:),Hb(11+1,:)))), 2^32);
W(14+1,:) = mod(bin2num(qnt32,sprintf('%-1d', xor(Mb(3+1,:),Hb(3+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(5+1,:),Hb(5+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(8+1,:),Hb(8+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(11+1,:),Hb(11+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(12+1,:),Hb(12+1,:)))), 2^32);
W(15+1,:) = mod(bin2num(qnt32,sprintf('%-1d', xor(Mb(12+1,:),Hb(12+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(4+1,:),Hb(4+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(6+1,:),Hb(6+1,:)))) - bin2num(qnt32,sprintf('%-1d', xor(Mb(9+1,:),Hb(9+1,:)))) + bin2num(qnt32,sprintf('%-1d', xor(Mb(13+1,:),Hb(13+1,:)))), 2^32);

Wb = num2bin(qnt32,W);
Wb = str2num(Wb(:));
Wb = reshape(Wb, 16, 32);   % W is stored into Wb as binary matrix

Q(0+1,:) = mod(bin2num(qnt32,sprintf('%-1d', s0(Wb(0+1,:)))) + H(1+1), 2^32);
Q(1+1,:) = mod(bin2num(qnt32,sprintf('%-1d', s1(Wb(1+1,:)))) + H(2+1), 2^32);
Q(2+1,:) = mod(bin2num(qnt32,sprintf('%-1d', s2(Wb(2+1,:)))) + H(3+1), 2^32);
Q(3+1,:) = mod(bin2num(qnt32,sprintf('%-1d', s3(Wb(3+1,:)))) + H(4+1), 2^32);
Q(4+1,:) = mod(bin2num(qnt32,sprintf('%-1d', s4(Wb(4+1,:)))) + H(5+1), 2^32);
Q(5+1,:) = mod(bin2num(qnt32,sprintf('%-1d', s0(Wb(5+1,:)))) + H(6+1), 2^32);
Q(6+1,:) = mod(bin2num(qnt32,sprintf('%-1d', s1(Wb(6+1,:)))) + H(7+1), 2^32);
Q(7+1,:) = mod(bin2num(qnt32,sprintf('%-1d', s2(Wb(7+1,:)))) + H(8+1), 2^32);
Q(8+1,:) = mod(bin2num(qnt32,sprintf('%-1d', s3(Wb(8+1,:)))) + H(9+1), 2^32);
Q(9+1,:) = mod(bin2num(qnt32,sprintf('%-1d', s4(Wb(9+1,:)))) + H(10+1), 2^32);
Q(10+1,:) = mod(bin2num(qnt32,sprintf('%-1d', s0(Wb(10+1,:)))) + H(11+1), 2^32);
Q(11+1,:) = mod(bin2num(qnt32,sprintf('%-1d', s1(Wb(11+1,:)))) + H(12+1), 2^32);
Q(12+1,:) = mod(bin2num(qnt32,sprintf('%-1d', s2(Wb(12+1,:)))) + H(13+1), 2^32);
Q(13+1,:) = mod(bin2num(qnt32,sprintf('%-1d', s3(Wb(13+1,:)))) + H(14+1), 2^32);
Q(14+1,:) = mod(bin2num(qnt32,sprintf('%-1d', s4(Wb(14+1,:)))) + H(15+1), 2^32);
Q(15+1,:) = mod(bin2num(qnt32,sprintf('%-1d', s0(Wb(15+1,:)))) + H(0+1), 2^32);

Qb = num2bin(qnt32,Q);
Qb = str2num(Qb(:));
Qb = reshape(Qb, size(Q,1), 32);   % Q is stored into Qb as binary matrix

```

Generated on Fri Sep 24 10:39:12 CEST 2010
Home