Esempio n. 1
0
        xV=list(xV)
        xV.sort()

        for i in range(5):
            yV.append([])
        #xV = range( min(x1,x2), max(x1,x2))
        for x in xV:
            for i in range(5):
                yV[i].append(scipy.stats.norm(self.mean[i], self.sd[i]).pdf(x))
        for i in range(5):
            plt.plot(xV, yV[i])
        plt.show()



if __name__ == "__main__":
    correctKey = "DEADBEEFCAFEBABE"
    sboxNum = 1
    roundNum = 1    # Do not Change this. Currently fixed to 1.
    rk = des_block.roundkey(correctKey,roundNum)   # Correct Round Key of roundNum
    sk = des_block.subkey(rk,sboxNum)             # Correct Sbox Key of roundNum, sboxNum
    samplePoint = 0

    acq = LoadTraces.LoadTraces('traces/0001.trs', samplePoint = 3881, numTraces = 100000)
    t = DES_PI(acq)
    #acq.shuffle()
    t.buildTemplate(0x1f, sboxNum, samplePoint, startTrace = 0, endTrace =100000)
    print "PI is %f" % (t.pi(0x1f, sboxNum, samplePoint, startTrace = 0, endTrace = 100000))


Esempio n. 2
0
        """Format the inputtext into format acceptable to des_block"""

        ptStr = ""
        for i in range(self.acq.blockSize):
            ptStr += hex2str(inputtext[i])
        return ptStr

if __name__ == "__main__":
    trsFile = '/Data/Documents/0007.trs'
    acq = LoadTraces.LoadTraces(trsFile, samplePoint = 39205)
    sboxNum = 1
    roundNum = 1    # Do not change this
    correctKey = "DEADBEEFCAFEBABE"
    leakage = 'HW'  # Use HW, HD or HDRound
    rk = des_block.roundkey(correctKey,roundNum)   # Correct Round Key of roundNum
    sk = des_block.subkey(rk,sboxNum)             # Correct Sbox Key of roundNum, sboxNum

    s = SNR(acq)
    #sig, noi = s.cpaTrace(sk, sboxNum, startTrace = 0, endTrace=10000, leakage = leakage)
    #samplePoint = np.argmax(np.abs(sig/noi))

    #print "Signal is %f, Noise is %f" % (sig[samplePoint], noi[samplePoint])
    #print "SNR is %f" % (sig[samplePoint]/noi[samplePoint])



    # Verify the accuracy using cross validation
    # Delete redundant samples and also randomise the order of the traces
    acq.shuffle()

    numTraceSNR = 1000 # acq.numTraces/10
Esempio n. 3
0
            distg[self.correctSubKey] = 0
            for i in range(64):
                if distg[i] > distCorrect:
                    rank += 1.0

        return rank / runs


if __name__ == "__main__":
    trsFile = 'traces/0001.trs'
    acq = LoadTraces.LoadTraces(trsFile, samplePoint=3881)
    correctKey = "DEADBEEFCAFEBABE"
    sboxNum = 1
    leakage = 'HW'
    roundNum = 1  # Do not Change this. Currently fixed to 1.
    rk = des_block.roundkey(correctKey,
                            roundNum)  # Correct Round Key of roundNum
    sk = des_block.subkey(rk, sboxNum)

    r = KRE(acq, sboxNum, sk, leakage=leakage)
    yKRE = []
    xKRE = []
    for i in range(15, 17, 2):
        yKRE.append(
            r.rank(i, samplePoint=0, attack='cpa', runs=10, leakage=leakage))
        xKRE.append(i)

    print yKRE
    print xKRE