示例#1
0
def main():
    parser = OptionParser()
    parser.add_option('', "--log-level", default="info",
                      help="Set log level: error, warning, info, debug, trace")
    parser.add_option('', "--rijndael", type='str',
                      help="Comma separated set of Rijndael's generalised"
                      "parameters. For example from the original Rijndael: "
                      "10,4,4,8 for 128, or 12,4,4,8,6 for 192 or "
                      "14,4,4,8,8 for 256 "
                      "(nRounds, nRows, nColumns, wordSize[, nKeyColumns])")
    import sys
    (options, args) = parser.parse_args()
    loglevel = levelFromMeaning(options.log_level)
    if options.rijndael is not None:
        parameters = extractParams(options.rijndael)
        now = datetime.now().strftime("%Y%m%d_%H%M%S")
        fileName = "%s_gRijndaelXORxtr.csv" % (now)
        doRijndael(fileName, *parameters)
    else:
        # BinaryPolynomialsXORCtr()
        # PolynomialRingXORCtr()
        # SBoxXORctr()
        # keyExpansionXORctr()
        # addRoundKeyXORctr()
        # subBytesXORctr()
        # mixColumnsXORctr()
        gRijndaelXORxtr()
示例#2
0
def main():
    parser = OptionParser()
    parser.add_option('', "--log-level", default="info",
                      help="Set log level: error, warning, info, debug, trace")
    parser.add_option('', "--rijndael", type='str',
                      help="Comma separated set of Rijndael's generalised"
                      "parameters. For example from the original Rijndael: "
                      "10,4,4,8 for 128, or 12,4,4,8,6 for 192 or "
                      "14,4,4,8,8 for 256 "
                      "(nRounds, nRows, nColumns, wordSize[, nKeyColumns])")
    import sys
    (options, args) = parser.parse_args()
    loglevel = levelFromMeaning(options.log_level)
    if options.rijndael is not None:
        parameters = extractParams(options.rijndael)
        rindaelTest = RindaelTest(options.log_level, *parameters)
        print("Encryption process")
        encryptionDiffusion(rindaelTest.encrypt)
        print("subBytes process")
        encryptionDiffusion(rindaelTest.subBytesDiffusion)
        print("shiftRows process")
        encryptionDiffusion(rindaelTest.shiftRowsDiffusion)
        print("mixColumns process")
        encryptionDiffusion(rindaelTest.mixColumnsDiffusion)
        print("subBytes & mixColumns process")
        encryptionDiffusion(rindaelTest.subBytesAndmixColumnsDiffusion)
示例#3
0
def main():
    parser = OptionParser()
    parser.add_option('', "--log-level", default="info",
                      help="Set log level: error, warning, info, debug, trace")
    parser.add_option('', "--test", type='str')
    parser.add_option('', "--rounds", type='int', default=0)
    parser.add_option('', "--key", type='int', default=0)
    import sys
    (options, args) = parser.parse_args()
    loglevel = levelFromMeaning(options.log_level)
    if options.test:
        if options.test.lower() in ["aes128", "aes192", "aes256"]:
            if options.test.lower() == "aes128":
                if options.rounds == 0:
                    result = test_AES128(loglevel)
                else:
                    result = test_AES128(loglevel, rounds=options.rounds)
            elif options.test.lower() == "aes192":
                if options.rounds == 0:
                    result = test_AES192(loglevel)
                else:
                    result = test_AES192(loglevel, rounds=options.rounds)
            elif options.test.lower() == "aes256":
                if options.rounds == 0:
                    result = test_AES256(loglevel)
                else:
                    result = test_AES256(loglevel, rounds=options.rounds)
            else:
                result = False
            if result:
                sys.exit(0)
            sys.exit(-1)
        else:
            rounds, nRows, nColumns, wordSize, nKeyColumns = \
                extractParams(options.test)
            expandKey(options.key, rounds, nRows, nColumns, wordSize,
                      nKeyColumns, options.log_level)
    else:
        for test in [test_AES128,
                     test_AES192,
                     test_AES256]:
            if not test(levelFromMeaning(options.log_level)):
                sys.exit(-1)
        sys.exit(0)
示例#4
0
def main():
    parser = OptionParser()
    parser.add_option('', "--log-level", default="info",
                      help="Set log level: error, warning, info, debug, trace")
    parser.add_option('', "--rijndael", type='str',
                      help="Comma separated set of Rijndael's generalised"
                      "parameters. For example from the original Rijndael: "
                      "10,4,4,8 for 128, or 12,4,4,8,6 for 192 or "
                      "14,4,4,8,8 for 256 "
                      "(nRounds, nRows, nColumns, wordSize[, nKeyColumns])")
    import sys
    (options, args) = parser.parse_args()
    loglevel = levelFromMeaning(options.log_level)
    if options.rijndael is not None:
        parameters = extractParams(options.rijndael)
        rindaelTest = DiffusionTest(options.log_level, *parameters)
        print("Encryption process")
        halfdiffusion = encryptionDiffusion(rindaelTest.encrypt)
        print("\n\tHalf-diffusion: %d" % (halfdiffusion))
        print("\tFull-diffusion: %d\n\n" % (halfdiffusion*2))
#         print("subBytes process")
#         if encryptionDiffusion(rindaelTest.subBytesDiffusion):
#             print("\n\tFull diffusion: %d\n\n" % (halfdiffusion*2))
#         print("shiftRows process")
#         if encryptionDiffusion(rindaelTest.shiftRowsDiffusion):
#             print("\n\tFull diffusion: %d\n\n" % (halfdiffusion*2))
#         print("mixColumns process")
#         if encryptionDiffusion(rindaelTest.mixColumnsDiffusion):
#             print("\n\tFull diffusion: %d\n\n" % (halfdiffusion*2))
#         print("subBytes & mixColumns process")
#         if encryptionDiffusion(rindaelTest.subBytesAndmixColumnsDiffusion):
#             print("\n\tFull diffusion: %d\n\n" % (halfdiffusion*2))
    else:
        now = datetime.now().strftime("%Y%m%d_%H%M%S")
        fileName = "%s_fulldiffusion.csv" % (now)
        with open(fileName, 'a') as f:
            f.write("rounds\trow\tcolumns\twordsize\tkolumns\tblock\tkey"
                    "\tfull-diffusion\n")
        for nRows in range(2, 9):
            for nColumns in range(2, 17):
                for wordSize in range(3, 17):
                    for nKolumns in range(2, 17):
                        if nKolumns >= nColumns:
                            nRounds = max(nKolumns, nColumns) + 6
                            blockSize = nRows*nColumns*wordSize
                            keySize = nRows*nKolumns*wordSize
                            rindaelTest = DiffusionTest(options.log_level,
                                                        nRounds, nRows,
                                                        nColumns, wordSize,
                                                        nKolumns)
                            halfdiffusion = \
                                encryptionDiffusion(rindaelTest.encrypt)
                            print("nRounds = %2d, nRows = %2d, "
                                  "nColumns = %2d, wordSize = %2d, "
                                  "nKeyColumns = %2d, blockSize = %4d, "
                                  "keySize = %4s -> full-diffusion = %2d"
                                  % (nRounds, nRows, nColumns, wordSize,
                                     nKolumns, blockSize, keySize,
                                     halfdiffusion*2))
                            with open(fileName, 'a') as f:
                                f.write("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n"
                                        % (nRounds, nRows, nColumns, wordSize,
                                           nKolumns, blockSize, keySize,
                                           halfdiffusion*2))