X-Git-Url: https://git.cryptolib.org/?p=avr-crypto-lib.git;a=blobdiff_plain;f=jh%2Fjh_tablegen.rb;h=47895969bb0e553ef4af27a93ad053892a686a1a;hp=5862a0e21193e5f325124a24e711c590b238b927;hb=4b5da1dc27a791b5c448274a3db09cd035b33493;hpb=bd740a03aa9137d46277a2eee05ac6be538ef69d diff --git a/jh/jh_tablegen.rb b/jh/jh_tablegen.rb index 5862a0e..4789596 100644 --- a/jh/jh_tablegen.rb +++ b/jh/jh_tablegen.rb @@ -2,7 +2,7 @@ # jh_tablegen.rb =begin This file is part of the AVR-Crypto-Lib. - Copyright (C) 2010 Daniel Otte (daniel.otte@rub.de) + Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -238,6 +238,30 @@ def single_round(data, round) return b end +def next_rc(data) + a = Array.new +=begin + printf("\n== rc round ==\n\t") + 4.times do |y| + 8.times do |x| + printf("%02X ", data[8*y+x]) + end + print("\n\t") + end +=end + 32.times do |idx| + x,y=split_byte($lutbox[0][data[idx]]) + a << x << y +# if(x==nil)or(y==nil) +# printf("DBG: idx=%2d, x=%2x, y=%2x", idx, x, y) +# end + end + a = permutation(a, 6) + b = Array.new + 32.times {|idx| b << join_nibbles(a[2*idx],a[2*idx+1])} + return b +end + def encrypt(data) =begin print("\n== ENCRYPT ==\n") @@ -345,3 +369,20 @@ end #=end puts("") +c0 = [ 0x6a, 0x09, 0xe6, 0x67, 0xf3, 0xbc, 0xc9, 0x08, + 0xb2, 0xfb, 0x13, 0x66, 0xea, 0x95, 0x7d, 0x3e, + 0x3a, 0xde, 0xc1, 0x75, 0x12, 0x77, 0x50, 0x99, + 0xda, 0x2f, 0x59, 0x0b, 0x06, 0x67, 0x32, 0x2a ] + +rc = c0 +42.times do |i| + printf("/* C_%02d: */\n", i) + 4.times do |y| + printf("\t") + 8.times do |x| + printf("0x%02x, ", rc[y*8+x]) + end + printf("\n") + end + rc = next_rc(rc) +end